Answer the question
In order to leave comments, you need to log in
Replacing regular quotes with herringbone quotes
Help me write a regular expression that would replace ordinary quotes " with typographic ones, taking into account html tags. Here (on Habré), for example, it does not work in all cases
"кавычка-елочка в произведении <a href="http://site.com">"Ель"</a>"
Answer the question
In order to leave comments, you need to log in
Arbitrary HTML cannot be parsed with regular expressions. Regulars cannot parse arbitrary HTML.
Regulars are not a tool for parsing HTML. As has already been said many times, it is impossible to parse arbitrary HTML with regular expressions.
Read more on StackOverflow .
This is either impossible or extremely difficult to do with 1 regex. You need to write an HTML parser (you can use the built-in DOM in PHP, but use ready-made solutions - for wimps), which will beat the input stream on the tag, the content of the attribute, the text between the tags, but already in the content of the attributes and the text between the tags change the form quotes.
Note that in HTML, a quotation mark can also be represented as §quot;
those.
<a href="http://site.com">& laquo;Ель& raquo;</a>"
jevix.ru/project/ it has autocorrect
Or use some typographer, for example www.artlebedev.ru/tools/typograf/
I remembered Spectator 's quotation mark , there is also a PHP-implementation.
to do this, you need to write an auxiliary f-th, which takes into account the closedness of the open quote. And use it regularly. It is not difficult, but it must take into account all the options. I won’t write right away (because now I’m a little “under a degree”).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question