Reputation: 671
Hi All i have the following string :
$sortable='record_69#record_83#record_70##'
how i can get all numbers(id) from that $sortable string? i try to do somthing like this:
preg_match_all('[0-9]', $sortable, $result, PREG_PATTERN_ORDER);
print_r($result);
but the result is Array ( [0] => Array ( ) ) i wnat $result to be like $result[0]=69......
Thank you
Upvotes: 1
Views: 97
Reputation: 1464
<?php
$sortable = "record_69#record_83#record_70#";
preg_match_all("/(\\d+)/", $sortable, $result, PREG_PATTERN_ORDER);
echo "<pre>";
print_r($result);
echo "</pre>";
?>
Upvotes: 0
Reputation: 36
preg_match_all('[0-9]+', $sortable, $result, PREG_PATTERN_ORDER);
Upvotes: 0
Reputation: 35927
The pattern [0-9]
takes only one number. You want to select more than one, so you have to use a quantifier :
preg_match_all('/record_([0-9]+)#/', $sortable, $result, PREG_PATTERN_ORDER);
You also need to add delimiters (/ in this case), and parenthesis to capture the numbers.
Upvotes: 4