dongzong2017 2013-05-09 08:33
浏览 48

在simplehtmldom中获取<br>标记之前的数据

I have a html tag as follows:-

<p>
"SOme important data1"
<br>
<br>
"SOme important data2"
<br>
<br>
"SOme important data3"
</p>

Now i want to get the data seperatley as "SOme important data1" SOme important data2 SOme important data3

I am using simple html dom. But i dnt knw hw to fetch this data.

What i have tried:-

echo $html->find('p',0)->plaintext;

But this prints all the data, Hw to fetch the data seperately...Please help me out... Thanks in advance

  • 写回答

1条回答 默认 最新

  • doubailian4459 2013-05-09 08:47
    关注

    An alternative depending on how you want the final data to be available in your code would be

    foreach (explode('<br>', $html->find('p',0)->innertext) as $item) {
        $data[] = trim(strip_tags($item));
    }
    
    var_dump($data); // just for testing
    

    Note the user if innertext rather than plaintext. This leaves the
    tags in the content to be used to split up the sentences into the array

    This will split up the <p> tag content on 1 of the <br> tags into an array, loop over it, remove any trailing whitespace and any other <br> tags and present the final list of strings as the values of an array $data

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度