我有一个文本块,包含以下内容:
[/+]There is my first text[+/]. There is my second text.
[/+]There is my third text.[+/]
There is my fourth text.
...
现在,我想将其拆分为2个字符串:
$str_1 = "There is my first text.";
$str_2 = " There is my second text.
[/+]There is my third text.[+/]
There is my fourth text. ...";
你能告诉我:“如何在PHP中将文本块拆分为2个字符串?”。
答案 0 :(得分:1)
答案 1 :(得分:1)
我不确定你的问题,但我认为你可能正在寻找这个
$str = "[/+]There is my first text[+/]. There is my second text.
[/+]There is my third text.[+/]
There is my fourth text.";
preg_match_all('/(\[\/\+])?([\w\s.]+)(\[\+\/])?/',$str,$m);
$str = "";
foreach($m[2] as $k => $v){
${"str".$k} = $v;
}
echo $str0."\n";
echo $str1."\n";
echo $str2."\n";
echo $str3."\n";