Re: Re: Using DOM object, how?

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

 



Stephen Leaf wrote:
On Monday 19 September 2005 05:27 am, Jasper Bryant-Greene wrote:

Ken Tozier wrote:

I don't see any obvious DOM method for including scripts or css links
like "<script language='text/javascript' src='bobo.js'>". Do you have
to put them in some other type of node like a processing instruction  or
a comment?

<?php
$dom = new DOMDocument('1.0', 'UTF-8');

$script = $dom->createElement('script');
$script->setAttribute('type', 'text/javascript');
$script->setAttribute('src', 'bobo.js');

$dom->appendChild($script);
?>

I would be extremely careful with this.. because sadly PHP's XML generator uses the short form whenever possible.
<script /> will *NOT* work in most browsers such as FireFox.
<script></script> Will work.

You can probably add an empty text node to the script tag, or a text node consisting of a single space, or something like that, to make it use the long form.

--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

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