Currently, I am replacing all my quotes inside the text with special quotes. But how can I change my regular expression, which will be replaced only with quotation marks inside the text, and not those used in html tags.
$text = preg_replace('/"(?=\w)/', "»", $text);
$text = preg_replace('/(?<=\w)"/', "«", $text);
I'm not used to regular expressions. The problem is that I need to replace the start quotes with a different character than end the quotes.
If you need more information, say so.
Any help is appreciated!
EDIT
Test case
<p>This is a "wonderful long text". At least it should be. Here we have a <a href="http://wwww.site-to-nowhere.com" target="_blank">link</a>.</p>
The expected result should be:
<p>This is a »wonderful long text«. At least it should be. Here we have a <a href="http://wwww.site-to-nowhere.com" target="_blank">link</a>.</p>
Now it looks like this:
<p>This is a »wonderful long text«. At least it should be. Here we have a <a href=»http://wwww.site-to-nowhere.com« target=»_blank«>link</a>.</p>
EDIT 2
thanks for Kamehameha's answer, I added the following code to my script:
$text = preg_replace("/\"([^<>]*?)\"(?=[^>]+?<)/", "»\1«", $text);
What worked great in the regex test doesn't replace anything. Did I do something wrong?