Re: PHP RegExp and HTML tags attributes values etc...

From: Date: Thu, 10 Mar 2005 09:54:38 +0000
Subject: Re: PHP RegExp and HTML tags attributes values etc...
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-210424@lists.php.net to get a copy of this message
Sorry for the spam.. here it is: <?php function tag_rep($tag) { return preg_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>&nbsp;key=value&nbsp;</a></span></font></p>"; $improved_html=preg_replace('/\<(.*)\>/Ue','"<".tag_rep("\1").">"',$html); echo str_replace("\\'","'",$improved_html); ?> :)

« previous php.general (#210424) next »