Reputation: 105
I have something like
Page 1 of 7 (1-49 of 325)
I need to find the last page by using regex.
Here is what i have as regex expression
<?php
$page = 'Page 1 of 7 (1-49 of 325)';
$matches = array();
$t = preg_match('/of(.*?)\(/s', $page, $matches);
print_r($matches[1]);
?>
It works fine, it outputs 7.
My problem is when ever i use
<?php
$page = file_get_contents('http://www.exaample.com');
$matches = array();
$t = preg_match('/of(.*?)\(/s', $page, $matches);
print_r($matches[1]);
?>
i get a lot of text, but i dont get the output '7'.
Upvotes: 3
Views: 158
Reputation: 2707
<?php
$str = 'Page 1 of 7 (1-49 of 325)';
preg_match('/\([0-9]+\-([0-9]+) of [0-9]+\)/', $str, $matches);
var_dump($matches);
Not tested.
Upvotes: -1
Reputation: 14691
This works:
$t = preg_match('/Page [0-9]+ of ([0-9]+)/i', $page, $matches);
Upvotes: 4