I have a string: “Blah blah blah “blah” blah blah”, and I need to replace quotes on this string to «Blah blah blah «blah» blah blah»
I was trying to use this script:
$m=preg_replace('/([^\s>])\\\"/s',"$1»",$m);
$m=preg_replace('/\\\"([^\s])/s',"«$1",$m);
But when the string beginning from the space, i have something like that:
»Some text» Some text Some text
How can I do this?
The most direct approach might be to use lookarounds to detect it the quote is directly before a word or directly after.
This will work well on your example, but may be too simplistic. You might want to go further and look for a word charactor or punctuation so “blah blah.” will match as well. That would make the second example something like this:
/(?<=[\w,.?!\)])"/