Answer the question
In order to leave comments, you need to log in
How to escape pattern with a variable so that preg_replace works?
Friends, welcome.
Can you please tell me how to properly process the variable for a successful preg_replace?
The $query variable is generated based on the user's request. What the user requested - must be highlighted.
If the code is like this, then the $contt variable returns NULL
$query = "/(\\[jkj|холо)/i";
<?=var_dump(preg_replace("/".$query."/i", "<b>$0</b>", $contt)));
$query = "/(\\[jkj|холо)/i";
<?=var_dump(preg_replace("/(\\[jkj|холо)/i", "<b>$0</b>", $contt)));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question