在PHP中使用爆炸函数处理值


process values in php by explode function

我有一个字符串- html文本

我想把字符串扩展成<'br>和<'p>一行。

提前感谢您的帮助。

例子
$text="hello <'p> this is the text <'br> split this text";
return
ar[0]=hello;
ar[1]=this is the text;
ar[2]=split this text;

编辑——使用preg_split

$str = "text1<p>text2<br/>text3";
$str = preg_split('/(<'s*p's*'/?>)|(<'s*br's*'/?>)/', $str);
print_r($str);
//*note wont work with you <'p> <'br> tags, but only real "< p>< /p>< br/>" tags

或者在标签中加上引号(不知道为什么会有)

 $str = "text1<'p>text2<'br>text3";
 $str = str_replace("<'p>","<'br>",$str);
 $values = explode("<'br>",$str);
 print_r($values);

这样就足够了:

$text="hello <'p> this is the text <'br> split this text";
$string = str_replace(array("<'p> ", "<'br> "), '___', $text);
$ex = explode('___', $string);
返回:

Array
(
    [0] => hello 
    [1] => this is the text 
    [2] => split this text
)

Example

由于其他两个答案都很糟糕,我建议:

$text="hello <'p> this is the text <'br> split this text";
$e=preg_split("#<'p>|<'br>#",$text);
print_r($e);

也许你可以…

$text = "hello <'p> this is the text <'br> split this text";
$text = str_replace("<'p>", "<'br>", $text);
$text = explode("<'br>", $text);

现在你得到你想要的