$str = "check-me-01";
if(preg_match("#(\d){0,}$#",$str)) {
$strArr = preg_split("#(\d){0,}$#",$str,2);
print_r($strArr);
}
I am using above script to get 01 from the string that can be any number.
but I always get
Array ( [0] => check-me- [1] => )
anybody can help me with this?
If you are trying to get 01 from that string, you should be using just preg_match, not preg_split. Visit that link, and examine how you can obtain the resulting matches.
Quote:
Note
&$matches. That’s what you want to look at more closely.preg_split will consume whatever it matches as the delimiter: that is the problem you are facing. Thus, whatever is matches will not be in the resulting array–only whatever is on either side.