【发布时间】:2011-09-30 04:59:26
【问题描述】:
我将首先简要介绍这实际上应该做什么......
获取网页的全部内容,转换为字符串,并保存到持久存储中。但是由于某种原因,它只是...不会?
我使用了 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>
【问题讨论】:
-
你有什么问题?什么错误信息?另外,考虑在 PHP 端使用 PHP 的
json_encode()进行字符串化。 -
我没想到/尝试过。查看页面源代码时,它只是呈现整个文本,显然是 html 实体格式,但不会在商店中添加任何内容...
标签: php javascript html