brianlange Posted June 6, 2011 Share Posted June 6, 2011 I need a regular expression that will remove all span tags that have a font-family css declaration. <span style="font-family: Times New Roman;"> I could probably write this but I need to know how to also remove the closing </span> tag. Thanks, Brian Quote Link to comment https://forums.phpfreaks.com/topic/238569-remove-span-tags-that-have-font-family-declaration/ Share on other sites More sharing options...
fugix Posted June 6, 2011 Share Posted June 6, 2011 note that $note will be the text that you are comparing preg_match_all('/<span style\=\"font\-family>(.*?)<\/span>/i', $note, $matches); Quote Link to comment https://forums.phpfreaks.com/topic/238569-remove-span-tags-that-have-font-family-declaration/#findComment-1225991 Share on other sites More sharing options...
requinix Posted June 6, 2011 Share Posted June 6, 2011 My version is smarter but more complicated. $note = one two three four END; do $note = preg_replace('#]+style="[^"]*font-family:[^"]*"[^>]*>(([^#is', '$1', $oldnote = $note); while ($oldnote != $note); echo $note; Quote Link to comment https://forums.phpfreaks.com/topic/238569-remove-span-tags-that-have-font-family-declaration/#findComment-1226057 Share on other sites More sharing options...
The Little Guy Posted June 10, 2011 Share Posted June 10, 2011 Why not just remove the font-family from the style tag? If you would like to do that, just do something like this: $new_string = preg_replace("/font-family\:.+?;/i", "", $string); Quote Link to comment https://forums.phpfreaks.com/topic/238569-remove-span-tags-that-have-font-family-declaration/#findComment-1227933 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.