PHP string split into 2 -
i've got string this
$str = "cl2" $str2 = "l1"
what i'm trying last numeric numer , whatever before numeric number
result want is
$result[0] = "cl" $result[1] = "2" $result[0] = "l" $result[1] = "1"
i've been looking @ explode() , str_split() php functions use cant seem find way last digit, else before thanks
this work me.you can split whatever before numeric number
<?php $str = "cl2"; $result = preg_split('/(?<=[a-z])(?=\d)/i', $str); ?>
another way @marcus's answer
<?php $str = "cl2"; $result = preg_split("/(\d+)/", $str , -1, preg_split_no_empty | preg_split_delim_capture); ?>
then result :
$result[0] = "cl" $result[1] = "2"
Comments
Post a Comment