This is my problem: I have my html document where I send via ajax two values: "id" and "a html string"
<div class="myClass"><h1 class="myClass">this is my html string </h1></div>
I receive this data in my .php file where I save the data in a .html file:
ajax code:
$(".button").on("click", function(e){
e.preventDefault();
var string = $(".htmlString").html();
$.ajax({
url: "data.php",
type: "post",
data: {
ID: "correctID",
htmlString: string
},
success: function(){
alert('ok');
},
error:function(){
alert('error');
}
});
});
php code:
if ($_POST['id'] == "correctID") {
$fileLocation = $_SERVER['DOCUMENT_ROOT'] . "/www/file.html";
$file = fopen($fileLocation,"w");
$content = $_POST['htmlString'];
fwrite($file,$content);
fclose($file);
}
the output .html file content is like:
<div class=\"myClass\"><h1 class=\"myClass\">
The PROBLEM as you see is the "\" before the quotes:
How can I save my file in a correct html format?
<div class="myClass"><h1 class="myClass">
Thanks a lot, was looking and I found DOMDocument::saveHTML but I could not use it, Im very new at PHP.., I really need the classes in my html file.