Re: PHP RegExp and HTML tags attributes values etc...
| From: | Eli | Date: | Thu, 10 Mar 2005 09:50:39 +0000 |
| Subject: | Re: PHP RegExp and HTML tags attributes values etc... | ||
| References: | 1 2 3 | Groups: | php.general php.general |
| Request: | Send a blank email to php-general+get-210423@lists.php.net to get a copy of this message | ||
Yup.. that was a good point.. ;)
Take a look at this example:
<?php
function tag_rep($tag)
{
return reg_replace('/(?<!\<)(\S+)\s*=\s*(?<![\'"])([^\s\'"]+)(?![\'"])/','\1="\2"',$tag);
}
$html="<p class=MsoNormal id=par><font size=3 face=\"Comic Sans MS\"><span lang=NL style='font-size:12.0pt;font-family:\"Comic Sans MS\"'><a href=http://www.php.net/index.php> key=value </a></span></font></p>";
$improved_html=preg_replace('/\<(.*)\>/Ue','"<".tag_rep("\1").">"',$html);
echo str_replace("\'","'",$improved_html);
?>