Reply to Re: PHP DOM XHTML - let me set my own javascript from code

Your name:

Reply:


Posted by Petr Smith on 10/19/05 16:21

Thanks a lot Rob, it's so simple! I don't know why I did't find it myself.

Petr

Rob wrote:
> Petr Smith wrote:
>
>> but it encloses it to CDATA section automatically like this:
>>
>> <script type="text/javascript"
>> language="Javascript"><![CDATA[alert('ddd');]]></script>
>>
>> but I need it like this (because otherwise the javascript don't work):
>>
>> <script type="text/javascript" language="Javascript">
>> //<![CDATA[
>> alert('ddd');
>> //]]>
>> </script>
>
>
> First, script was using some bogus method names.
> Secondly, you try to do anything like the following (which do work)?
>
> $html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
> \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n".
> " \n".
> "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\"
> lang=\"en\">\n".
> "<head>\n" .
> " <script type=\"text/javascript\" language=\"Javascript\" />\n" .
> "</head>\n" .
> "<body>hello\n" .
> "</body>\n" .
> "</html>";
> $dom = new DomDocument();
> $dom->preserveWhiteSpace = true;
> $dom->loadXML($html);
> $params = $dom->getElementsByTagName('script');
> foreach ($params as $param) {
> $dat = $dom->createTextNode("\n//");
> $param->appendChild($dat);
> $dat = $dom->createCDATASection("\n\nalert('ddd');\n\n//");
> $param->appendChild($dat);
> $dat = $dom->createTextNode("\n");
> $param->appendChild($dat);
> }
> echo $dom->saveXML();
>
> Could also do it using <!-- --> through a comment node (following adds
> some linefeeds too):
> foreach ($params as $param) {
> $dat = $dom->createTextNode("\n");
> $param->appendChild($dat);
> $dat = $dom->createComment("\n\nalert('ddd');\n\n");
> $param->appendChild($dat);
> $dat = $dom->createTextNode("\n");
> $param->appendChild($dat);
> }

[Back to original 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

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