"replace string only once with php preg_replace" Answer’s

0

You are looking for preg_quote instead of trying to escape the yourself (which doesn't take [, + and many others into account):

$return = preg_replace('/'.preg_quote($remove,'/').'/', $replace, $string, 1);
Wednesday, March 31, 2021
 
Fredy
answered 10 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share