我是下面的函数,我在努力输出DOMDocument而没有在内容输出之前附加XML,HTML,body和p标签包装器.建议的修复:
$postarray['post_content'] = $d->saveXML($d->getElementsByTagName('p')->item(0));
Run Code Online (Sandbox Code Playgroud)
仅在内容中没有块级元素时才有效.但是,当它执行时,如下面的例子中的h1元素,saveXML的结果输出被截断为...
<p>如果你喜欢</ p>
我已经指出这篇文章可能是一种解决方法,但是我无法理解如何将它实现到这个解决方案中(参见下面的注释).
有什么建议?
function rseo_decorate_keyword($postarray) {
global $post;
$keyword = "Jasmine Tea"
$content = "If you like <h1>jasmine tea</h1> you will really like it with Jasmine Tea flavors. This is the last ocurrence of the phrase jasmine tea within the content. If there are other instances of the keyword jasmine tea within the text what happens to jasmine tea."
$d = new DOMDocument();
@$d->loadHTML($content);
$x = new DOMXpath($d);
$count = …Run Code Online (Sandbox Code Playgroud) 我正在创建一个Node.js webscraper/proxy,但是我在解析源代码的脚本部分中找到的相对Urls时遇到了问题,我认为REGEX可以解决这个问题.虽然我不知道如何实现这一目标.
无论如何我可以解决这个问题吗?
此外,我对这样做更容易,因为我对其他代理如何解析网站感到困惑.我认为大多数只是美化的网站刮刀,可以读取网站的来源中继所有链接/表格回到代理.