Re: replace n first occurences of a char in a string
| From: | Jason Barnett | Date: | Sat, 24 Jul 2004 02:39:19 +0000 |
| Subject: | Re: replace n first occurences of a char in a string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-191721@lists.php.net to get a copy of this message | ||
Then, once I have determined there are more than one dot, how can I remove all the dots but the right most one?You can replace a limited number of matches using preg_replace(). <?php $number = '123.456.789.10'; $count = substr_count($number, '.'); $number = preg_replace('/\./', '', $number, $count - 1); echo $number; ?>
so 123.456.789.01 would become 123456789.01 with just the dot before the zero. Thanks in advance.