我正在尝试将一个javascript文件加载到PHP页面中,然后我可以使用jquery加载将该数据加载到我的网站中。
http://www.themoviequotes.com/widgets/javascript?n=1&l=1&g=3这是URL。如果你把它放到浏览器中,它会显示document.write等,然后显示我想要的实际内容。
我可以使用哪个函数来获取数据,我已经尝试过file_get_contents,但它返回了所有的html/javascript标记etc...like:
document.write("
Finding Forrester (2000)
William Forrester: Writers write things to give readers something to read.
"); 发布于 2010-12-06 05:47:57
<?php
$quote = file_get_contents('http://www.themoviequotes.com/widgets/javascript?n=1&l=1&g=3');
$quote_text = array();
preg_match('!document\.write\(\"(.+)\"\);!', $quote, $quote_text);
$quote_text = stripslashes($quote_text[1]);
echo($quote_text);如果你想获取javascript中的值,你也可以重写document.write()函数作为回调函数,将引号插入到你的dom中的某个地方。
发布于 2010-12-06 05:33:54
将脚本标记放在您想要放置内容的位置,并将src属性设置为该地址。
<script type="text/javascript" src="http://www.themoviequotes.com/widgets/javascript?n=1&l=1&g=3"></script>发布于 2010-12-06 05:34:11
你的意思是你想在PHP中执行JavaScript?为此,您需要一个解析器/JavaScript引擎。这并不是说Javascript神奇地工作;浏览器包含了实现这一点的逻辑,并执行Javascript代码,但我不知道是否有任何Javascript库来实现这一点。
在这种情况下,您可以通过使用一些字符串函数或正则表达式来去除代码中的所有html和javascript,并保留标题和文本。
https://stackoverflow.com/questions/4361322
复制相似问题