I'm pretty new to PHP and have a String which contains an HTML page. I'd need to insert some custom code BEFORE and AFTER any HR HTML tag. Example:
<html>
....
<p>INSERT HERE</p>
<hr class="pagebreak">
<p>INSERT HERE</p>
<p>INSERT HERE</p>
<hr class="pagebreak">
<p>INSERT HERE</p>
....
</html>
I've tried with several combinations of preg_replace and substr_replace, however I still couldn't manage to insert the custom code in all places I need. Anybody can help me to solve this puzzle ? P.s. I need to use PHP standard String functions- I cannot use any HTML parsing library since I don't have control over the PHP libraries available on the server. Thanks a lot Linda
All you need to get is good regular expression, assuming that you managed to get it work at least partially, you propably had bad expression (example would help). I tested this code for you and it should work on all your
<hr>
s:variable oldtext is what you had before, new text is what you want, and prefix and suffix is what you want to add around hr tag