Only replace first matching element using PHP's mb_ereg_replace
Posted
by Mark L
on Stack Overflow
See other posts from Stack Overflow
or by Mark L
Published on 2010-03-29T09:53:56Z
Indexed on
2010/03/29
10:13 UTC
Read the original article
Hit count: 377
Hello,
I want to replace only the first matching element in a string instead of replacing every matching element in a string
$str = 'abc abc abc';
$find = 'abc';
$replace = 'def';
echo mb_ereg_replace( $find, $replace, $str );
This will return "def def def".
What would I need to change in the $find or $replace parameter in order to get it to return "def abc abc"?
© Stack Overflow or respective owner