例:
<div>foo</div>
<p>bar</p>
Unwrapped text
私が欲しいもの:
<div>foo</div>
<p>bar</p>
<span>Unwrapped text</span>
新しいラインに依存せずにこれを達成する方法は?
HTMLには正規表現を使用しません。
$doc = phpQuery::newDocument($html);
$doc->contents()->not($doc->children())->wrap("<span>");
$html = $doc->html();
しかし、それを試しませんでした。
たとえば、、、、、、、、、のように文字列<div>
からfoo
トークンを</div>
抽出<p>
します。これは正規表現で行うことができます。それでbar
</p>
Unwrapped text
for each token do
if token is opening tag
push token on stack
else if token is closing tag (and matching opening tag is ontop of stack)
pop token from stack
else if token is text and stack is not empty
ignore token (continue)
else if token is text and stack is empty
wrap token with <span>
これは、任意のネストされた文字列に対して機能しXML
ます。