In the following string, I would like to delete "class2" and "class3" in the class attribute of the span tag
Right now, I'm doing this:
$string = '<span class="class1 class2 class3">class1 class2 class3</span>';
$patterns = array();
$patterns[0] = '/class2/';
$patterns[1] = '/class3/';
$replacements = array();
$replacements[0] = '';
$replacements[1] = '';
$string = preg_replace($patterns, $replacements, $string);
echo htmlspecialchars($string);
This returns:<span class="class1 ">class1 </span>
This not exactly what I want.
I would like it to return: <span class="class1">class1 class2 class3</span>
I don't know what kind of pattern I have to to use to make the replacements only inside the class attribute
Thanks for your help!