我有这个示例字符串。
$string = "There four of them. These are: 1 The first one. Its is the most common. 2 The second one. 3 The third one. 4 This is the last.";
我想分割成包含上述$string
中给出的信息的数组。我想让它看起来像这样。
Array (
[0] => The first one. Its is the most common.
[1] => The second one.
[2] => The third one.
[3] => This is the last.
)
有谁能帮我吗?谢谢你。 您可以使用preg_split
将字符串分割为整数,例如:
$string = "There four of them. These are: 1 The first one. Its is the most common. 2 The second one. 3 The third one. 4 This is the last.";
$matches = preg_split('/'d+/', $string);
var_dump($matches);
您可以在preg_match_all()
中使用regex来选择字符串的目标部分。
preg_match_all("/'d+([^'d]+)/", $string, $matches);
print_r($matches[1]);
参见demo