We are looking to add some hairline spacing to punctuation to improve the appearance of a webpage's typography. Adding the hairline spacing to change (what)
to ( what )
seems pretty straight forward using str_replace, several times to cover the four main punctuation marks.
str_replace("(", "( ", $content);
str_replace(")", " )", $content);
str_replace("?", " ?", $content);
str_replace("!", " !", $content);
BUT we need to limit the replacement process to only the content within the main div <div id="main">bla (bla) bla</div>
as the targeted punctuation marks ( ? ! )
are also used by the CSS, JS, etc on that page.
The pages will have been minified before the space insertion is applied, so comments, line breaks and such will have been stripped out and not a concern.
Is there a way to target just a section of the content string?
And a second concern would be how to avoid targeting ?
within a link url? Basically trying to ignore items within an <a href=url'>
that is within the main div.
THIS QUESTION WAS NOT A DUPLICATE OF THE OTHER ONE WHICH ASKED ABOUT EXTRACTING INFO. THIS ONE IS ABOUT MODIFYING INDIVIDUAL ALPHANUMERIC CHARACTERS IN A WEBPAGE.