PHP 简单 html Dom 无法读取 (br/) 换行符
PHP Simple html Dom can't read (br/) newline
我正在学习使用解析器,简单 html dom。
示例代码:
<?php
include('simple_html_dom.php');
$html = str_get_html('<div class="column-2"><h1>Hey </h1><p>Gold Bar</p><p>Where are you?<br/>I am here<br/></p>');
foreach($html->find('p') as $br){
$value[]=$br->outertext;
}
echo $value[1];
?>
结果:
Where are you?
I am here
如果我想要 $html:
的结果怎么办
Where are you?
或
I am here
您需要使用 explode()
http://php.net/manual/en/function.explode.php
进一步拆分字符串以获取 <br/>
之前或之后的字符串
include('simple_html_dom.php');
$html = str_get_html('<div class="column-2"><h1>Hey </h1><p>Gold Bar</p><p>Where are you?<br/>I am here<br/></p>');
foreach($html->find('p') as $br){
$value[]=explode("<br/>", $br->outertext);
}
echo $value[1][0];
我正在学习使用解析器,简单 html dom。
示例代码:
<?php
include('simple_html_dom.php');
$html = str_get_html('<div class="column-2"><h1>Hey </h1><p>Gold Bar</p><p>Where are you?<br/>I am here<br/></p>');
foreach($html->find('p') as $br){
$value[]=$br->outertext;
}
echo $value[1];
?>
结果:
Where are you?
I am here
如果我想要 $html:
的结果怎么办Where are you?
或
I am here
您需要使用 explode()
http://php.net/manual/en/function.explode.php
<br/>
之前或之后的字符串
include('simple_html_dom.php');
$html = str_get_html('<div class="column-2"><h1>Hey </h1><p>Gold Bar</p><p>Where are you?<br/>I am here<br/></p>');
foreach($html->find('p') as $br){
$value[]=explode("<br/>", $br->outertext);
}
echo $value[1][0];