【问题标题】:How to Remove the href link in dom parser如何删除dom解析器中的href链接
【发布时间】:2013-08-08 14:18:29
【问题描述】:

html代码:

<tr class="dd1">
<td>Aug 27, 2013</td>

<td>
<a href="/schedule/1588-zimbabwe-vs-pakistan-1st-odi-match.php" class="url">Zimbabwe vs Pakistan</a><b>, 1st ODI</b>
</td>   

<td>
<a href="/venue/harare.php">Harare</a>
</td>

php代码:

$html = file_get_html('http://www.cricschedule.com/format/odi.php');

$es = $html->find('table td');

echo "$ea[4]";

我想要这样的输出:
津巴布韦 vs 巴基斯坦,第一次 ODI

但我得到这样的输出:
Zimbabwe vs Pakistan, 1st ODI

【问题讨论】:

标签: php parsing dom


【解决方案1】:

您可以在字符串上使用strip_tags 函数。

http://php.net/manual/en/function.strip-tags.php

$html = file_get_html('http://www.cricschedule.com/format/odi.php');
$es = $html->find('table td');

echo strip_tags($es[4]);

【讨论】:

    【解决方案2】:

    您可以使用http://php.net/manual/en/function.strip-tags.php

    echo strip_tags($es[4]);
    

    【讨论】:

      【解决方案3】:

      使用strip_tags()

      $html = file_get_html('http://www.cricschedule.com/format/odi.php');
      $es =  $html->find('table td');
      echo strip_tags( $ea[4] );
      

      【讨论】:

      • 为什么 strip_tags 你已经在使用正确的工具,所以它读取 a 的值而不是
      【解决方案4】:

      试试这个

      str_replace(",",".",trim(rtrim(strip_tags('<a href="/schedule/1588-zimbabwe-vs-pakistan-1st-odi-match.php" class="url">Zimbabwe vs Pakistan</a>'))));
      

      【讨论】:

        【解决方案5】:

        根据: http://simplehtmldom.sourceforge.net/ (点击刮斜线)

        $es[4]->plaintext;
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-02-28
          • 2011-10-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多