PHP inserting some text before and after a string

Solution:1

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:

$newtext=preg_replace("#(<hr[^>]*>)#s",$yourprefix."\${1}".$yoursuffix,$oldtext);

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

Solution:2

$before = '<p>Before the hr tag</p>';
$after = '<p>After the hr tag</p>';

$str = preg_replace('/(<hr(.*?)>)/i',$before.'$1'.$after,$str);