PHP解析HTML字符串的方式 [英] PHP way of parsing HTML string

查看:100
本文介绍了PHP解析HTML字符串的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php字符串,它包含从RSS提要中检索的下面的HTML。我正在使用简单的饼图,无法找到从< description> 获取的这两个数据集的其他拆分方式。如果有人知道在简单的饼图中选择一个好的孩子的方法。

I have a php string that contains the below HTML I am retrieving from an RSS feed. I am using simple pie and cant find any other way of splitting these two datasets it gets from <description>. If anyone knows of a way in simple pie to select children that would be great.

<div style="example"><div style="example"><img title="example" alt="example" src="example.jpg"/></div><div style="example">EXAMPLE TEXT</div></div>

to:

$image = '<img title="example" alt="example" src="example.jpg">';
$description = 'EXAMPLE TEXT';


推荐答案

$received_str = 'Your received html';

$html = str_get_html($received_str);

//Image tag
$img_tag = $html->find("img", 0)->outertext;

//Example Text
$example_text = $html->find('div[style=example]', 0)->last_child()->innertext;

请参阅: http://simplehtmldom.sourceforge.net/manual.htm

这篇关于PHP解析HTML字符串的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆