Hi,
I have this var: $i="141job_id"
but it can also be: $i="12due_date";
I need to extract the number form the expression. How can I do that?
Thanks, Assaf
If the number is always at the beginning of the string, then simply convert the string to an integer:
$string = "141job_id"; $i = (int)$string; // $i = 141;
Quite handy, really!!
If it's not always at the beginning, you could do a simple [man]preg_match/man like so:
$string = "something1823else"; preg_match('/\d+/', $string, $number); $number = $number[0];
Note that this only works for positive integers.
Thanks guys 🙂