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
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.
preg_match_all('[0-9] +',$ sortable,$ result,PREG_PATTERN_ORDER);
<?php
$sortable = "record_69#record_83#record_70#";
preg_match_all("/(\\d+)/", $sortable, $result, PREG_PATTERN_ORDER);
echo "<pre>";
print_r($result);
echo "</pre>";
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.