PHP シンプル HTML DOM パーサーを使用して、ホームページからの完全な html を持つ simple_html_dom オブジェクトのヘッド内に新しいスクリプト タガを追加することは可能ですか?
そのテンプレート内にいくつかのノードを追加する必要があります。このノードの 1 つは jquery を含むスクリプト タグであり、もう 1 つはデータベースから取得するテキストを含む 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);