|
Posted by BlackDex on 10/04/10 11:10
Thx... it works almost :P
I Changed the code a bit so you can see the results quicker :).
It doesn't change every attribute/value. I think this has to do something
with the opening and closing of a tag <>.
My code:
---
<?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> key=value </a></span></font></p>";
echo 'Normal HTML:<br><textarea cols="70" rows="10">';
echo $html;
echo "</textarea><br><br>";
$improved_html = preg_replace('/\<(.*)\>/Ue','"<".tag_rep("\1").">"',$html);
echo 'Improved HTML:<br><textarea cols="70" rows="10">';
echo str_replace("\\'","'",$improved_html);
echo "</textarea>";
?>
---
"Eli" <eli.hen@gmail.com> wrote in message
news:4230195E.4040404@gmail.com...
> 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> key=value </a></span></font></p>";
>
> $improved_html=preg_replace('/\<(.*)\>/Ue','"<".tag_rep("\1").">"',$html);
> echo str_replace("\\'","'",$improved_html);
> ?>
>
> :)
Navigation:
[Reply to this message]
|