SV: Javascript backslash in php dom object

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

 



Addslashes() breaks the js code:

<?php
$html = '
<html>
	<head>
		<style>'.file_get_contents("http://ol3js.org/en/master/css/ol.css";).'</style>
		<script type="text/javascript">'.file_get_contents("http://ol3js.org/en/master/build/ol.js";).'</script>
	</head>
	<body>
		<div id="map"></div>
    	<script type="text/javascript">
      		var map = new ol.Map({
        		target: "map",
        		renderer: "canvas",
        		layers: [
          			new ol.layer.Tile({
            			title: "Global Imagery",
            			source: new ol.source.TileWMS({
              				url: "http://maps.opengeo.org/geowebcache/service/wms";,
              				params: {LAYERS: "bluemarble", VERSION: "1.1.1"}
            			})
         			})
        		],
        		view: new ol.View2D({
          			projection: "EPSG:4326",
          			center: [0, 0],
          			zoom: 0,
          			maxResolution: 0.703125
        		})
      		});
    	</script>
	</body>
</html>';
$htmlslashes = addslashes($html);
echo $htmlslashes;  //works not
//echo $html; works
?>

/H
________________________________________
Från: Gaasbeek | Communiq [gaasbeek@xxxxxxxxxxx]
Skickat: den 9 maj 2014 15:29
Till: Uggla Henrik; php-general@xxxxxxxxxxxxx
Ämne: Re:  Javascript backslash in php dom object

Adding addslashes() makes it return the script though.

<?php
$html = '<html><head><script type="text/javascript">'.file_get_contents("http://ol3js.org/en/master/build/ol.js";).'</script></head><body></body></html>';
$html = addslashes($html);
$dom = new DOMDocument();
$dom->loadHTML($html);
$html2 = $dom->saveHTML();
echo $html2;  //works not
//echo $html;
?>

Met vriendelijke groet,

Meint-Willem Gaasbeek

Communiq BV
Walstraat 18
8011 NT Zwolle

Telefoon 038-426 00 60
Email gaasbeek@xxxxxxxxxxx
Internet www.communiq.nl

De informatie verzonden met dit e-mail bericht is uitsluitend bestemd voor de geadresseerde. Gebruik van deze informatie door anderen dan de geadresseerde is verboden. Openbaarmaking, vermenigvuldiging, verspreiding en/of verstrekking van deze informatie aan derden is niet toegestaan zonder voorafgaande toestemming. Communiq staat niet in voor de juiste en volledige overbrenging van de inhoud van een verzonden e-mail, noch voor tijdige ontvangst daarvan. Tevens staat Communiq niet in voor het virusvrij zijn van een verzonden e-mail.




Op 9 mei 2014, om 14:51 heeft Uggla Henrik het volgende geschreven:

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


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