开发者

PHP preg_split   [0-9]  

开发者 https://www.devze.com 2023-03-21 13:49 出处:网络
Hi i need to split a string into an array based on this \"dynamic\" separator: String   1  String2

Hi i need to split a string into an array based on this "dynamic" separator:

String   1  String2

String2   65  String3

The number between the   it's variable... also the strings could contain   too, so 开发者_如何学JAVAa str_replace or an explode it's useless (for me)


$str = "String   1   ";
$result = preg_split('/   [\d]+  /', $str);
print_r($result);

Array
(
    [0] => String
    [1] =>  
)

Explanation:

# Match the characters “   ” literally «   »
# Match a single digit 0..9 «[\d]+»
#    Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
# Match the characters “  ” literally «Â  »
0

精彩评论

暂无评论...
验证码 换一张
取 消