Re: Re: Replacing first character in a string

From: Date: Thu, 01 May 2003 12:59:19 +0000
Subject: Re: Re: Replacing first character in a string
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-145940@lists.php.net to get a copy of this message
--- Hugh Bothwell <hugh_bothwell@hotmail.com> wrote: > > "Lee P. Reilly" <lreilly@lanl.gov> wrote in message > news:3EB02C14.79845983@lanl.gov... > > I wonder if anyone can help me? I have a string something like > this: > > ",.00109863,.00219725,.00329588.... and so on....". > > > > If the *first character* in the string is a comma (as in the case > above) > > then I want to replace it with "0,", but I cannot find a way to > do it. > > Of all the replies, only one was > correct, and it was pretty obfuscated. > Try this: > > if (substr($str,0,1) == ",") > $str = "0" . substr($str,1); Actually, from the original post, this will specifically NOT do what he asks. Whether it's what he actually wants is something else. He asks to replace the comma with a zero and a comma (actually, prepend a zero), not replace the comma with a zero, which is what your "correct" script does. Make the last line: $str = "0" . $str; and it'll do what is asked. ===== Mark Weinstock mark_weinstock@yahoo.com *************************************** You can't demand something as a "right" unless you are willing to fight to death to defend everyone else's right to the same thing. *************************************** __________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. http://search.yahoo.com

« previous php.general (#145940) next »