I need an if()
function to do this:
preg_replace()
letters (a
, b
, c
, etc.) except for those wrapped in tags (<p>
, <b>
, <span>
, etc.) and exclude the letters if they are part of a certain word.
$string = "<p>replace everything inside tags <b>only</b> </p>exception";
$patterns = array();
$patterns[0] = '/e/';
$patterns[1] = '/b/';
$patterns[2] = '/s/';
$replacements = array();
$replacements[2] = '-e-';
$replacements[1] = '-b-';
$replacements[0] = '-s-';
echo preg_replace($patterns, $replacements, $string);
I want "<p>
", "<b>
" and the word "exception" to remain unaltered.