duanlao6573 2014-03-12 23:49
浏览 66
已采纳

无法解析成<code>标签 - PHP - 简单的html dom

I am trying to extract the content of a <div> nested inside a <code> tag with PHP Simple HTML DOM Parser but I am always getting the error Trying to get property of non-object in... as if the parser was finding nothing inside my <div>

The code I'm using is

include_once('simplehtmldom_1_5/simple_html_dom.php');

// Create a DOM object
$html = new simple_html_dom();

// Load HTML
$html->load('<code><div>hello</div></code>');

// Extract div content
echo $html->find('div',0)->innertext;

But if instead of using <code><div>hello</div></code> as my sample code i use <span><div>hello</div></span> it works... it seems like I'm having problems only looking inside the code tag.

What's wrong with what i'm doing? Hope you guys can point me in the right direction, thank you very much for your support!

  • 写回答

2条回答 默认 最新

  • duanao4729 2014-03-13 00:09
    关注

    simplehtmldom among others strips out pre formatted tags. If you want code tag to be recognized delete or comment out line 1076 in *simple_html_dom.php*

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解