dongshaidu2456 2016-05-17 11:29
浏览 54
已采纳

如何从简单的html dom中的html标签获取欲望innertext

I have some text in which there is codes. I want to get last text from the link. here is an example

Some text<a href="http://beezfeed.cu.ma">Beezfeed.cu.ma</a><br>
another text<a href="http://google.com">Google.com</a><br>

I want to get Google.com text from the above code. I have tried and use Simple html dom. Anyway Here is my code

   <?PHP
require_once('simple_html_dom.php');
$html = new simple_html_dom();
function tags($ddd){
$bbb=$ddd->find('a',1);
    foreach($bbb as $bs){
    echo $bs->innertext;
    }
}
$html = str_get_html('Some text<a href="http://beezfeed.cu.ma">Beezfeed.cu.ma</a><br>
another text<a href="http://google.com">Google.com</a><br>');

echo tags($html);
?> 

I want to get Google.com how to get. Please help me

  • 写回答

1条回答 默认 最新

  • dt246813579 2016-05-17 11:37
    关注

    I strongly recommend you use some external library to parse HTML. Any HTML you need. As you need today or in future needs. Some very good tools are named inside these stackoverflow post.

    I personally use simplehtmldom.sourceforge.net since ages with very good results.

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

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据