SV: Javascript backslash in php dom object

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

 



I don't want each client downloading the script from http://ol3js.org separately. The script should be loaded by the server, cached and delivered to the clients.

/H
________________________________________
Från: Frank Arensmeier [farensmeier@xxxxxxxxx]
Skickat: den 12 maj 2014 11:02
Till: Uggla Henrik
Kopia: php-general@xxxxxxxxxxxxx
Ämne: Re:  Javascript backslash in php dom object

12 maj 2014 kl. 10:44 skrev Uggla Henrik <Henrik.Uggla@xxxxxxxxxxxxxxx>:

> Php doesn't like <![CDATA[ either:
>
> <?php
> $html = '<html><head><script type="text/javascript"><![CDATA[]]></script></head><body></body></html>';
> $dom = new DOMDocument();
> $dom->loadHTML($html);
> $html2 = $dom->saveHTML();
> echo $html2;  //works not
> ?>
>
> /Henrik
> ________________________________________
> Från: Frank Arensmeier [farensmeier@xxxxxxxxx]
> Skickat: den 9 maj 2014 15:30
> Till: Uggla Henrik
> Kopia: php-general@xxxxxxxxxxxxx
> Ämne: Re:  Javascript backslash in php dom object
>
> 9 maj 2014 kl. 14:51 skrev Uggla Henrik <Henrik.Uggla@xxxxxxxxxxxxxxx>:
>
>> I'm trying to add some js code (from Openlayers3) to a php dom object. Echoing the html with the js code directly works but not after it is loaded into the dom. I get "SyntaxError: illegal character" in Firefox. I think it's the backslashes in the js code thats the problem. How could I make it work? I've tried htmlspecialchars but it didn't work.
>>
>> <?php
>>
>> $html = '<html><head><script type="text/javascript">'.file_get_contents("http://ol3js.org/en/master/build/ol.js";).'</script></head><body></body></html>';
>> $dom = new DOMDocument();
>> $dom->loadHTML($html);
>> $html2 = $dom->saveHTML();
>> echo $html2;  //works not
>> // echo $html works
>>
>> ?>
>>
>> /HU
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php

This seems all very backwards to me. Is there any particular reason why you want to load javascript code into the DOMDomcument prior to echoing out the HTML? Your probably won’t be able to do anything with the script element what so ever. 2Why not simply write like:

$jsurl = "http://ol3js.org/en/master/build/ol.js";;
$html = <<<HTML
<html>
        <head>
                <script type="text/javascript" src="{$jsurl}"></script>
        </head>
        <body>
        </body>
</html>
HTML;
$dom = new DOMDocument();
$dom->loadHTML($html);
$html2 = $dom->saveHTML();
echo $html2;

/frank

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