dongyouzhui1969 2014-10-16 15:12
浏览 21

DomDocument - >输出已更改的html

below is my current code that pulls the html

BEFORE

<td class="winner betting-movement">
                11/8<img src="/images/site/blue-arrow-small.gif" width="6" height="11">6/4          </td>

Then replaces images with text

After

 <html><body><td class="winner betting-movement">$movement =  $article->childNodes->item(12)->ownerDocument->saveHTML($article->childNodes->item(12))."<br />";



                    <? php @$dom3->loadHTML($movement);
                     $xpath5 = new DOMXPath($dom3);
                    foreach($xpath5->query('//img[contains(@src, "blue")]') as $link) {
    $link->parentNode->replaceChild($dom3->createTextNode(" > "), $link);
}
                    foreach($xpath5->query('//img[contains(@src, "red")]') as $link) {
    $link->parentNode->replaceChild($dom3->createTextNode(" < "), $link);
}
                echo    $dom3->saveHTML();?>

works great but all i need to do now is output the new saved html as just the inner text e.g "11/8 > 6/4"

echo    $dom3->saveHTML()->textContent;

sadly the last line doesn't work and im reaching out to see if anyone could point me in a quick fix for this?

  • 写回答

1条回答 默认 最新

  • duangou1953 2014-10-16 15:19
    关注

    Can you do echo htmlentities($dom3->saveHTML()); - this would encode the HTML to be viewable to the user. More info: http://php.net/manual/en/function.htmlentities.php

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog