I will begin by briefing as to what this actually should do…
Fetch the entire contents of a web page, turn into a string, and save into persistant storage. However for some reason, it just… wont?
Ive used php’s html entities, and then JSON Stringify, however it just fails to work.
My code is as follows…
//arrays set above
$url = "http://www.google.co.uk";
$handle = fopen($url, "r");
$contents = stream_get_contents($handle);
$contents = htmlentities($contents);
echo "<script lang='text/javascript'>var dataString = JSON.stringify('".$contents."'); tokens[".$t." = ".$rowtokens[5]."]; toStore[".$t." = dataString]; alert('CONTENT'); </script>";
EDIT :
That source code renders the following
<script lang='text/javascript'>tokens[0 = tokenvalue here]; toStore[0 = "<!DOCTYPE html PUBLIC "-//W3C//DTD X...
//All the rest of the html of the page.
"];localStorage.setItem(token[0], toStore[0]);</script>
You mean:
Currently it is evaluating to:
which is invalid and does not do what you want:
If your code returns this:
then it’s not valid:
<script type='text/javascript'>0 = tokenvalue here(you’re storing something in the number0, which is not possible). Don’t you meantokens[0] = tokenvalue?