Re: PHP RegExp and HTML tags attributes values etc...
| From: | Eli | Date: | Thu, 10 Mar 2005 02:15:08 +0000 |
| Subject: | Re: PHP RegExp and HTML tags attributes values etc... | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-210407@lists.php.net to get a copy of this message | ||
Eli wrote:
Try: preg_replace('/(?<=\<)([^>]*)(\w+)=(?<!\'|\")([^>\s]+)(?=\s|\>)([^<]*)(?=\>)/U','\1\2="\3"\4',$html); Hmm.. that could be a start.. and don't ask me how it works... :PWell.. problem with that, is that if you got more than 1 un-escaped attribute in a tag, the regex will fix only the first un-escaped attribute. for example, if $html is: <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"'> </span></font></p> In that case the id=par will remain as is... Does anyone knows how to improve it?