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.

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

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题