PHP DOM XHTML - let me set my own javascript from code

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

 



Hi,

I have problem with PHP DOM extension. How can I add my own javascript to javascript tag?

I tried it using this code

$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->createTextSection("\n\nalert('ddd');\n\n");
    $param->appendChild($dat);

}
echo $dom->saveXML();

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>

Thanks for any idea,

Petr

--
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