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 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用