在php中为每个html元素创建新的数组值
我正试图将此字符串:在php中为每个html元素创建新的数组值,php,arrays,string,Php,Arrays,String,我正试图将此字符串: > President Obama pointed blabla<br /> <br /> The only way I get this > stuff <br /> <br /> I'm consulting with the Pentagon, with <br /> <br > /> 我尝试使用explode(“,$string),但它不起作用。有什么想法吗?尝试在explo
> President Obama pointed blabla<br /> <br /> The only way I get this
> stuff <br /> <br /> I'm consulting with the Pentagon, with <br /> <br
> />
我尝试使用
explode(“
,$string)
,但它不起作用。有什么想法吗?尝试在explode
函数中的
标记之间添加一个空格。看起来您只需要删除每行的前两个字符(“>”),连接所有行,然后进行分解(注意缺少的空格,正如其他人指出的那样)。在您的情况下explode(“
,$string);
可以
更一般地说,如果有一些行由
,“
,$string”分隔,有些行由
分隔,有些行由
分隔,则可以在前一行前面添加:
,,除非是打字错误,否则在explode()中缺少空格在每个之间。或者,您可以执行以下操作:
array (
[0] => President Obama pointed blabla
[1] => The only way I get this stuff
[2] => I'm consulting with the Pentagon, with
);
$br2arr = array_filter(preg_split("/([\s\b]*<br \/>[\s\b]*)|([\s\b]*<br>[\s\b]*)/", $str));
$br2arr=array_filter(preg_split(“/([\s\b]*
[\s\b]*))|([\s\b]*
[\s\b]*)/”,$str);
在任何情况下,它都可以执行您想要的操作/格式分解(“
,$string)
请注意2个
之间的空格。