PHP: preg_split 与第一个描述的字符

PHP: preg_split with the first described char

我有这样的字符串:

bla bla: [blabla: "bla"]

我想按字符分解它 ":" 正如你所看到的,我有两个位置的这个字符,但我只想按第一个字符拆分它
所以我想要的结果是:

1- bla bla
2- [blabla: "bla"]

如何使用 preg_split 实现此目的?

请尝试:

list($before, $after) = explode(':', $source, 2);

这就是您要找的,

$string = 'bla bla: [blabla: "bla"]';
$arr = preg_split("#:#", $string,'2');
print_r($arr);

limit If specified, then only substrings up to limit are returned with the rest of the string being placed in the last substring. A limit of -1, 0 or NULL means "no limit" and, as is standard across PHP, you can use NULL to skip to the flags parameter.

工作code