Reputation: 363
On click I'm creating a new .html webpage. My HTML code is stored in a variable called content. But finally when the webpage is the made, the code automatically has \" (it escapes the double quotes). Is there a way for me to do it so that the webpage doesn't have escaped double quotes?
HTML CODE:
<html>
<body>
<button onclick="makePage()">Generate Link</button>
<script src="makePage.js">
</script>
<script>
var img = document.getElementById("img").value;
var content = document.getElementById("content").value;
</script>
</body>
</html>
JAVASCRIPT CODE:
function makePage(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200)
alert("webpage " + xmlhttp.responseText + " was successfully created!");
}
var content = '<html><head><meta name="twitter:card" content="summary_large_image"><meta name="twitter:site" content="@nytimes"><meta name="twitter:creator" content="@SarahMaslinNir"><meta name="twitter:title" content="Parade of Fans for Houston’s Funeral"><meta name="twitter:description" content="NEWARK - The guest list and parade of limousines with celebrities emerging from them seemed more suited to a red carpet event in Hollywood or New York than than a gritty stretch of Sussex Avenue near the former site of the James M. Baxter Terrace public housing project here."><meta name="twitter:image" content="http://graphics8.nytimes.com/images/2012/02/19/us/19whitney-span/19whitney-span-articleLarge.jpg"></head><body></body></html>';
xmlhttp.open("GET","http://ahansabharwal.com/makePage.php?content=" + content, true);
xmlhttp.send();
}
PHP CODE:
<?php
$content = $_GET["content"];
$file = "" . uniqid() . ".html";
file_put_contents($file, $content);
echo $file;
?>
Upvotes: 3
Views: 314
Reputation: 45829
It sounds as if magic_quotes_gpc is enabled in PHP (this is deprecated in later versions of PHP). In which case you'll need to call stripslashes() on the $_GET
value before processing it.
Something like:
<?php
$content = $_GET['content'];
if (get_magic_quotes_gpc()) {
$content = stripslashes($content);
}
You should also be URL encoding the content
before sending it in the GET request (the encodeURIComponent()
method in JavaScript). However, this is a lot to send via GET, consider using a POST request instead.
Upvotes: 3