regex - How to replace the first occurrence only of any item in a list/array? (PHP) -
i have text this:
paul loves anna, anna loves john, , john loves betty. unluckily, betty loves paul. paul hates anna because loves john. john loves betty, , that's why anna sad. anna marry paul, it's late.
and need replace first occurrence of each name. need use preg_replace_callback
? there simpler solution?
preg_replace (as preg_replace_callback) accept parameter limit number of time replaces something.
http://php.net/manual/en/function.preg-replace.php
i'm not patterns should able figure pattern , use like
preg_replace($patterns, "", $string, 1);
i can't see how more simple can get
Comments
Post a Comment