I am using fwrite to add javascript to a external script. In order to do this there needs to be a php string with the java inside. However the " and ' get mixed up and I am not sure how to fix it. Here Is the code:
$page =
"<script type="text/javascript">
function outf(text) {
var mypre = document.getElementById("output");
mypre.innerHTML = mypre.innerHTML + text;
}
function builtinRead(x) {
if (Sk.builtinFiles === undefined || Sk.builtinFiles["files"][x] === undefined)
throw "File not found: '" + x + "'";
return Sk.builtinFiles["files"][x];
}
function runit() {
var prog = document.getElementById("yourcode").value;
var mypre = document.getElementById("output");
mypre.innerHTML = '';
Sk.canvas = "mycanvas";
Sk.pre = "output";
Sk.configure({output:outf, read:builtinRead});
try {
eval(Sk.importMainWithBody("<stdin>",false,prog));
}
catch(e) {
alert(e.toString())
}
}
</script>
<?php
fwrite($fh, $page); ?>
The Script does what I want it to do, however the speech marks within the javascript mix with the php string speech marks as you can see above, causing the php to throw an error. Is there a way to fix this?
Thanks
$page =
"<script type=\"text/javascript\">
function outf(text) {
var mypre = document.getElementById(\"output\");
mypre.innerHTML = mypre.innerHTML + text;
}
function builtinRead(x) {
if (Sk.builtinFiles === undefined || Sk.builtinFiles[\"files\"][x] === undefined)
throw \"File not found: '\" + x + \"'\";
return Sk.builtinFiles[\"files\"][x];
}
function runit() {
var prog = document.getElementById(\"yourcode\").value;
var mypre = document.getElementById(\"output\");
mypre.innerHTML = '';
Sk.canvas = \"mycanvas\";
Sk.pre = \"output\";
Sk.configure({output:outf, read:builtinRead});
try {
eval(Sk.importMainWithBody(\"<stdin>\",false,prog));
}
catch(e) {
alert(e.toString())
}
}
</script>";
<?php
fwrite($fh, $page);
?>