为php中的每个html元素创建新的数组值


Create new array value for each html element in php

我正在尝试转换这个字符串:

> President Obama pointed blabla<br /> <br /> The only way I get this
> stuff <br /> <br /> I'm consulting with the Pentagon, with <br /> <br
> />

进入该阵列:(每个"<br /> <br />"的新阵列元素)

array (
[0] => President Obama pointed blabla
[1] => The only way I get this stuff 
[2] => I'm consulting with the Pentagon, with 
);

我试着使用explode("<br /><br /> ", $string),但它不起作用。有什么想法吗?

看起来您只需要删除每行的前两个字符(">"),连接所有行,然后进行分解(注意缺少的空格,正如其他人所指出的)。

在您的情况下,explode("<br /> <br />", $string);可以工作。

更一般地说,如果您有一些行由<br /> <br />分隔,而一些行则由<br /><br /> 分隔,则可以在前一行之前添加:$string = str_replace('<br /> <br />', '<br /><br />', $string);

尝试在explode函数中的<br />标记之间添加一个空格。

除非是打字错误,否则您的explode()中每个
之间都缺少一个空格。或者你可以做:

$br2arr = array_filter(preg_split("/(['s'b]*<br '/>['s'b]*)|(['s'b]*<br>['s'b]*)/", $str));

在任何情况下/格式