How could I convert something like this:
\"hi (text here) and (other text)\" come (again)
To this:
\"hi \\(text here\\) and \\(
This should do it for both single and double quotes:
$str = '"hi \(text here)" and (other text) come \'(again)\'';
$str = preg_replace_callback('`("|\').*?\1`', function ($matches) {
return preg_replace('`(?
output
"hi \(text here\)" and (other text) come '\(again\)'
It is for PHP >= 5.3. If you have a lower version (>=5) you have to replace the anonymous function in the callback with a separate function.