Looking for the best solution on how to replace regular quotes within a block of text with curly quotes, but not to change quotes found within html tag markers <....> I have attempted using preg-replace, such as:
$pattern = '/(?<!=)"\b/';
$lyrics = preg_replace($pattern, "\u201c", $lyrics);
$pattern = '/\b"(?!>)/';
$lyrics = preg_replace($pattern, "\u201d", $lyrics);
$pattern = '/\."/'; // find regular quotes after a period
$lyrics = preg_replace($pattern, ".\u201d", $lyrics);
$pattern = '/\!"/'; // find regular quotes after an exclamation
$lyrics = preg_replace($pattern, "!\u201d", $lyrics);
$pattern = '/"\s/'; // find regular quotes before a space
$lyrics = preg_replace($pattern, "\u201d ", $lyrics);
For example, if I have the following:
<a href="http://somelink.com">"This is a quotation."
I want it to end up as:
<a href="http://somelink.com">“This is a quotation.”