Solution:1
The key is to use the correct regular expression. If your previous attempt didn’t work properly, it was likely due to an incorrect pattern (sharing your attempt would help). I tested the following code, and it should work for all your
tags:
$newtext = preg_replace(
"#(<hr[^>]*>)#s",
$yourprefix . "$1" . $yoursuffix,
$oldtext
);
$oldtext → your original string.
$newtext → the updated string after replacements.
$yourprefix / $yoursuffix → the text or HTML you want to add before and after each
tag.