Re: replace question.
| From: | Andreas Pour | Date: | Mon, 11 Sep 2000 14:02:55 +0000 |
| Subject: | Re: replace question. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-16179@lists.php.net to get a copy of this message | ||
Jason Granum wrote:
>
> I'm trying to do an ereg_replace however I only want to replace the 1st
> match in the text, not every match. I've scoured through the manual but
> can't figure anything out. Basicly I'm looking for the equivilent to
> Perls s/find/replace/; not s/find/replace/g; -- Thanks for any help
Off the top of my head . . . how about
preg_replace("@^(.*?)($regex)(.*)$@", "\1$replace\2", $string);
Add qualifies as needed.
You can use ereg for this but the problem is I don't think it has the
non-greedy option so I think it would replace the last rather than the
first occurrence.
Ciao,
Andreas Pour
http://www.kde.com/ : Everything KDE
http://apps.kde.com/: The Latest in KDE Applications