[英]PHP Regex match and split then catch all values in the same array
I have some string values like我有一些字符串值,例如
Pattern: n digit number, , words模式:n位数字,,,字
I want to get:我想得到:
(1) (1)
["30", "abcd efgh"]
(2) (2)
["35", "xyz PQRS"]
(3) (3)
["50", "DEF xyz"]
How can I do this?我怎样才能做到这一点?
Why load a whole regex engine, you can do this with explode()
为什么要加载整个正则表达式引擎,您可以使用
explode()
$in = '30 abcd efgh';
$bits = explode(' ', $in, 2);
print_r($bits);
RESULT结果
Array
(
[0] => 30
[1] => abcd efgh
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.