RE: [PHP] Replacing first character in a string
| From: | John W. Holmes | Date: | Wed, 30 Apr 2003 23:35:15 +0000 |
| Subject: | RE: [PHP] Replacing first character in a string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-145869@lists.php.net to get a copy of this message | ||
> 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.
$str = ($str{0}==',' ? '0' : '') . $str;
or
if($str{0}==',') { $str = '0' . $str; }
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/