php vs regex for counting data -
i have array, have same data:
data range 115x0101-115x0200 115x0101-115x0200 115x0101-115x0200
the 115x mean production code..this unimportant. concern @ 4 digits behind can counting.
1. want script read or search "0101" , "0200" 115x0101-115x0200 2. have tried using regex count them become 200-101=100 3. "115x0101-115x0200" repeated until there 20 data 4. after reached 20, show result @ page: data range 100
if raw data, easiest way extract using regular expression, you've mentioned.
you'll want (in php):
# database $sql_results = array( '115x0101-115x0200', '115x0101-115x0200', '115x0101-115x0200', ); foreach($sql_results $row) { preg_match_all('/\d{4}/', $row, $matches); #200 #101 echo intval($matches[0][1]) - intval($matches[0][0]) + 1; }
for each row, preg_match find groups of 4 digits (\d{4}
) , place them in $matches
(use var_dump($matches)
see looks like).
more on regex
sql limit
side note: if want 20 results @ time, you'll want select * table limit 20
when query database. rows 31-50 you'd use limit 30, 20
, means offset 30, 20 rows.
Comments
Post a Comment