I dont think a Preg_Match is gonna get you what you want in all cases... I found this on the web, you should be able to manipulate this to get what you want.
function strip_attributes($msg, $tag, $attr, $suffix = “”)
{
$lengthfirst = 0;
while (strstr(substr($msg, $lengthfirst), “<$tag “) != “”) {
$tag_start = $lengthfirst + strpos(substr($msg, $lengthfirst), “<$tag “);
$partafterwith = substr($msg, $tag_start);
$img = substr($partafterwith, 0, strpos($partafterwith, “>”) + 1);
$img = str_replace(” =”, “=”, $img);
$out = “<$tag”;
for($i = 0; $i < count($attr); $i++) {
if (empty($attr[$i])) {
continue;
}
$long_val =
(strpos($img, ” “, strpos($img, $attr[$i] . “=”)) === false) ?
strpos($img, “>”, strpos($img, $attr[$i] . “=”)) – (strpos($img, $attr[$i] . “=”) + strlen($attr[$i]) + 1) :
strpos($img, ” “, strpos($img, $attr[$i] . “=”)) – (strpos($img, $attr[$i] . “=”) + strlen($attr[$i]) + 1);
$val = substr($img, strpos($img, $attr[$i] . “=”) + strlen($attr[$i]) + 1, $long_val);
if (!empty($val)) {
$out .= ” ” . $attr[$i] . “=” . $val;
}
}
if (!empty($suffix)) {
$out .= ” ” . $suffix;
}
$out .= “>”;
$partafter = substr($partafterwith, strpos($partafterwith, “>”) + 1);
$msg = substr($msg, 0, $tag_start) . $out . $partafter;
$lengthfirst = $tag_start + 3;
}
return $msg;
}
The function takes 4 parameters.
1 $msg. The text you want to strip attributes from.
2 $tag. The tag you want to strip attributes fom (p, for instancee).
3 $attr. An array with the name of the attributes you want to strip (leaving the rest intact). If the array is empty, the function will strip all attributes.
4 $suffix. An optional text to append to the tag. It may be a new attribute, for instance.