是否可以使用 PHP Simple HTML DOM 解析器在 simple_html_dom 对象的头部添加一个新的脚本标记,该对象具有主页的完整 html?
我需要在该模板中添加一些节点,其中一个节点是带有 jquery 的脚本标记,另一个是一个 div,其中包含我从数据库中提取的一些文本。
我以前做过这样的事情:(使用 DOMDocument )
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->loadHTML($remote);
$head = $dom->getElementsByTagName('head')->item(0);
$jquery = '$(document).ready(function(){ $("#feed_home").hide()});
if (window.location.hash) {
Destino = window.location.hash.replace(\'#!\', \'?\');
window.location.href = window.location.href.split(\'#\')[0] + Destino;
}
';
$script = $dom->createElement('script', $jquery);
$script_type = $dom->createAttribute('type');
$script_type->value = 'application/javascript';
$script->appendChild($script_type);
$head->appendChild($script);
PHP 简单 HTML DOM 允许操作:
$html = str_get_html($rawhtml);
$inject = '<script type="text/javascript">alert("Hello")</script>';
$html->find('head', 0)->innertext = $inject.$html->find('head', 0)->innertext;
echo $html;
http://simplehtmldom.sourceforge.net/manual.htm#frag_access_tips http://simplehtmldom.sourceforge.net/manual.htm#frag_access_tips
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)