我有以下html:
<div><p>Launched:</p> <p>2010</p><p>Categories:</p><p>Software</p><p>Description:</p><p>Established</p><p>Website:</p></div>
如果我加载它并使用明文只获取文本:
$str = '<div><p>Launched:</p><p>2010</p><p>Categories:</p><p>Software</p><p>Description:</p><p>Established</p><p>Website:</p></div>';
$html = str_get_html($str);
echo $html->plaintext;
结果是不同的p标签之间没有空格:
发布时间:2010类别:软件描述:已建立网站:
如果我在结束和开始的p标记之间添加一个空格,它将正确输出。
这是正确的行为吗?
有没有一种方法可以让解析器在明文输出中考虑p标签?
标签p之间必须有空格,否则可以这样做:
$result = "";
foreach($html->find('p') as $val){
$result .= $val->plaintext." " ;
}
u可以通过这种方式剥离标签
$content = file_get_contents($url);
$rawContent = strip_tags($content);
$html = str_get_html($content);