4

QueryPath を使用して、と埋め込み<div>が混在するサイトの埋め込みビデオをラップしています。<object><iframe>

次のコードを試しました:

    $content = qp($content)
    ->find('object,iframe,a.evdPlayer')
    ->wrap('<div class="splashBack"></div>')
    ->top('body')->children()
    ->html(); // << It's wanting to remove the </iframe> Grrr.
return $content;

<iframe></iframe>しかし、コードをに変更したいよう<iframe />で、何らかの理由で混乱しています。ラッピングしているタグを変更しないようにする方法はありますか?

前もって感謝します!

4

2 に答える 2

4

->html メソッドは、DOMDocument::saveXML を使用する場合、LIBXML_NOEMPTYTAG フラグを設定しません。終了タグが必要な場合は、このフラグを渡す代わりに ->xhtml を使用する必要があります。例えば

    $content = qp($content)
    ->find('object,iframe,a.evdPlayer')
    ->wrap('<div class="splashBack"></div>')
    ->top('body')->children()
    ->xhtml();
    return $content;
于 2012-04-26T00:56:15.673 に答える
2

うまくいくように見える解決策を見つけました。...クエリパスの間にコンテンツを挿入すると、終了タグの必要性が認識され、そのままになります。これはハックですが、今のところは機能します。

$content = qp($content)
    ->find('object,iframe,a.evdPlayer')
    ->text('[ video embed ]')
    ->wrap('<div class="splashBack"></div>')
    ->top('body')->children()
    ->html(); // << It's wanting to remove the </iframe>
return $content;
于 2011-12-14T08:27:52.153 に答える