如何使用PHP将文本块拆分为2个字符串?

如何使用PHP将文本块拆分为2个字符串?,php,string,Php,String,我有一个文本块,包含以下内容: There is my first text. --- There is my second text, 1. There is my second text, 2. ... 现在,我想将其拆分为两个字符串: $str_1=这是我的第一个文本。; $str_2=这是我的第二个文本,1。 这是我的第二篇课文,2。; 如何使用PHP将文本块拆分为2个字符串 注: 1. -- 可以是更多,例如:--,-。。。 2.这是我的第一篇课文。始终是文本块的开头 因为,我的

我有一个文本块,包含以下内容:

There is my first text.

---

There is my second text, 1.
There is my second text, 2.
...
现在,我想将其拆分为两个字符串:

$str_1=这是我的第一个文本。; $str_2=这是我的第二个文本,1。 这是我的第二篇课文,2。; 如何使用PHP将文本块拆分为2个字符串

注: 1. -- 可以是更多,例如:--,-。。。 2.这是我的第一篇课文。始终是文本块的开头

因为,我的文本结构改变了。所以,我的问题有一些微小的变化。我为此感到荣幸。

差不多

$arr = explode("\n", $str)
将生成具有以下内容的数组

[0] = [*]There is my first text
[1] = 
[2] = There is my second text, 1
[3] = There is my second text, 2
他是你的朋友。使用[*]作为分隔符分解文本块,并在其上使用以删除第一个空元素

$str = "[*]There is my first text.[*]

There is my second text, 1.
There is my second text, 2.";
$result = array_filter(explode("[*]", $str));
执行后,第一个文本将显示在$result[0]中,第二个文本将显示在$result[1]中

编辑:更改需求后,请使用:


这将使用任意数量的“-”作为分隔符来分隔文本

使用分解功能您将获得我的投票,以便使用正确的方式并利用preg_split。
$str = "There is my first text.

---

There is my second text, 1.
There is my second text, 2.";
print_r(preg_split("/-+/", $str));