我有一个 php 字符串,其中包含我从 RSS 提要中检索的以下 HTML。我正在使用简单的饼图,但找不到任何其他方法来拆分它从 <description>
获得的这两个数据集。 .如果有人知道在简单的馅饼中选择 child 的方法,那就太好了。
<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;
关于PHP解析HTML字符串的方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6083076/