我将首先介绍一下这实际上应该做什么......
获取网页的全部内容,转换为字符串,并保存到持久存储中。但由于某种原因,它只是......不会?
我使用了 php 的 html 实体,然后使用了 JSON Stringify,但是它无法工作。
我的代码如下...
//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>";
编辑:
该源代码呈现以下内容
<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>
最佳答案
你的意思是:
tokens['".$t."'] = '".$rowtokens[5]."';
目前正在评估:
tokens[something = test];
这是无效的并且不执行您想要的操作:
- 一切都发生在属性名称内;没有设置任何内容
- 您没有可能会弄乱事情的引号
如果您的代码返回以下内容:
<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>
那么它无效:
- 这是
<script type='text/javascript'>
- 我不知道你的
0 = tokenvalue here
是什么意思(您正在数字0
中存储一些内容,这是不可能的)。你不是说tokens[0] = tokenvalue
? - 有换行符,因此您应该删除它们,因为当前有一个未终止的字符串
关于php - 通过 PHP 脚本中运行的操作将大型变量存储在 HTML5 持久存储中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7598889/