doq70020 2015-09-04 15:45
浏览 171

使用DOM提取div标签之间的内容,但保留其他html标签

I whant to extract the content betwin the tags from html file with DOM.

source file:

<html>
<body>
some html code
..........
<div id="text"> 
<p>some title</p> <br>
<p>some text</p> <br>
<img src="../images2/somegif.gif">
<div>
..........
</body>
</html>

my code:

$file = 'somefile.html';
include('simple_html_dom.php');
$html = new simple_html_dom();
$html->load_file($file);
$text = $html->getElementById('text');

echo $text;

the result is:

<div id="text"> 
<p>some title</p> <br>
<p>some text</p> <br>
<img src="../images2/somegif.gif">
<div>

What I want is just the data inside the div tags but keeping all the other HTML elements like:

<p>some title</p> <br>
<p>some text</p> <br>
<img src="../images2/somegif.gif">

How can I do that? ...I need that data to send to a mysql DB later on. Thank you.

  • 写回答

1条回答 默认 最新

  • douxishai8552 2015-09-04 18:45
    关注
    $text1= $html->getElementById('text');
    $text= $text1->innertext;
    echo $text;
    

    I just change the var names ...LOL

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料