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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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);
?>

:)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux