String replacement problems...
| From: | John Clegg | Date: | Tue, 23 Dec 2003 16:01:13 +0000 |
| Subject: | String replacement problems... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-173249@lists.php.net to get a copy of this message | ||
Hi
I am trying to figure out how to get ereg_replace / preg_replace to replace a match only once.
Here is my example:
$text = "[foo] bah [foo] moo [foo] boo\n";
$ans = ereg_replace("\[foo\]{1}","FOO",$text);
or
$ans = preg_replace("/\[foo\]{1}/",$text,"FOO");
The answer I get for both I run the example
echo $ans;
FOO bah FOO moo FOO boo
Can any tell me what I am doing wrong ? I am trying only to replace the match once. eg
FOO bah [foo] moo [foo] boo
Any help would be appreciated...
Cheers
John Clegg