Reputation: 119
I got a simple php issue which is that I don't know how to use substring here...
ABCDEF[RAND NUMBER 1-10000000]GH
And so I need to get that random number using substring,
I dont know if my brain works correctly today but I really couldnt figure how to do that.
Upvotes: 0
Views: 119
Reputation: 50667
Regular expressions are better when you don't know where in the text is desired substring,
$string = "ABCDEF10000000GH";
if (preg_match("/(\d+)/", $string, $m)) {
print $m[1];
}
Upvotes: 3
Reputation: 1322
Regex is always better in this case but If your string pattern is fixed like ABCDEF123456GH, you can simply use substr like
$str = "ABCDEF432465GH";
echo substr($str, 6, -2);
Upvotes: 3
Reputation: 3858
This will do, no need for substr
or anything:
$string='ABCDEF432465GH';
echo preg_replace('/[a-z\[\] ]*/i', '', $string);
Upvotes: 3