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条)

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码