1
打印HTML代碼中DOMXPath未出現於屏幕
...
我創建了修改特定頁面的輸出小腳本:
foreach ($markers as $marker) {
foreach ($xpath->query('//text()[not(ancestor::a) and not(ancestor::pre) and not(ancestor::code) and not(ancestor::img) and not(ancestor::script) and not(ancestor::style)]') as $node) {
$text = $marker[ 'text' ];
$url = $marker[ 'url' ];
$tip = strip_tags($marker[ 'excerpt' ]);
$tooltip = ($tooltip ? "data-uk-tooltip='' title='$tip'" : "");
$replaced = preg_replace(
'/\b' . preg_quote($text, "/") . '\b/i',
"<a href='$url' $hrefclass target='$target' $tooltip>\$0</a>",
$node->wholeText
);
$newNode = $dom->createDocumentFragment();
$newNode->appendXML($replaced);
$node->parentNode->replaceChild($newNode, $node);
}
}
$event->setContent(utf8_encode($dom->saveHTML()));
現在我有一個問題:
如果頁面內容包含一個<pre><code><strong>some-content</strong></code></pre>
這些元素不會顯示爲文本 - 它們會被解析爲源代碼。
所以也沒有顯示文本<strong>some-content</strong>
但分析它,並顯示一些內容
可惜這是不可能的,因爲我的腳本編輯的CMS的看法。如果網站管理員正在使用此CMS的突出顯示插件,則使用'
'輸出不應打包到收件箱。 – SPQRInc