You are here: Re: PHP RegExp and HTML tags attributes values etc... « PHP « IT news, forums, messages
Re: PHP RegExp and HTML tags attributes values etc...

Posted by BlackDex on 10/04/21 11:10

Owkay i fixed it :D.
The regexp needed a /s (Pattern Modifier) also so that the "."(DOT) also does newlines :).
Now it is fixed...

Thank you very much Eli :)

/me is happy.

THE 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>&nbsp;key=value&nbsp;</a></span></font></p>";

echo 'Normal HTML:<br><textarea cols="70" rows="10">';
echo $html;
echo "</textarea><br><br>";

$improved_html = preg_replace('/\<(.*)\>/Ueis','"<".tag_rep("\1").">"',$html);
echo 'Improved HTML:<br><textarea cols="70" rows="10">';
echo str_replace("\\'","'",$improved_html);
echo "</textarea>";
?>
---



"BlackDex" <black.dex@lycos.nl> wrote in message news:20050310140600.25321.qmail@lists.php.net...
> 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 <>.
>
<CUT>
> ---
>
> "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>&nbsp;key=value&nbsp;</a></span></font></p>";
>>
>> $improved_html=preg_replace('/\<(.*)\>/Ue','"<".tag_rep("\1").">"',$html);
>> echo str_replace("\\'","'",$improved_html);
>> ?>
>>
>> :)

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация