dqrzot2791 2016-04-02 09:04
浏览 44
已采纳

PHP简单HTML DOM - 如何获取标记内的文本

I use PHP Simple HTML Dom to get some HTML, now I have a HTML dom like follow code, I need fetch the plain text inner a tag, but I am getting the text link(Kiwi Fruit Basket).

HTML Code

<div class="name" style="height: 34px;">
    <a href="http://floristchennai.com/kiwi-basket">Kiwi Fruit Basket</a>
</div>

Php Code

 // Create DOM from URL or file
 $html = file_get_html('http://floristchennai.com/');

 // Find all links text
 foreach($html->find('.name a') as $element) 
 {
    echo "<br>a tag text value=" . $element;
 }

Doing it this way I don't get the text I want to get.

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • dsbtwy1329 2016-04-02 09:09
    关注

    try: innertext() innertext used for Read or write the inner HTML text of element.

        foreach($html->find('.name a') as $element) 
        {
            echo "<br>a tag text value=" . $element->innertext;
        }
    

    API Ref

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 outlook无法配置成功
  • ¥15 Pwm双极模式H桥驱动控制电机
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换