我有类似
的东西Page 1 of 7 (1-49 of 325)
我需要使用正则表达式找到最后一页。
这就是我所拥有的正则表达式
<?php
$page = 'Page 1 of 7 (1-49 of 325)';
$matches = array();
$t = preg_match('/of(.*?)\(/s', $page, $matches);
print_r($matches[1]);
?>
工作正常,输出7。
我的问题是什么时候使用
<?php
$page = file_get_contents('http://www.exaample.com');
$matches = array();
$t = preg_match('/of(.*?)\(/s', $page, $matches);
print_r($matches[1]);
?>
我得到了很多文字,但我没有得到输出'7'。
答案 0 :(得分:4)
这有效:
$t = preg_match('/Page [0-9]+ of ([0-9]+)/i', $page, $matches);
答案 1 :(得分:0)
使用此正则表达式\d+(?=\s*\()
答案 2 :(得分:-1)
<?php
$str = 'Page 1 of 7 (1-49 of 325)';
preg_match('/\([0-9]+\-([0-9]+) of [0-9]+\)/', $str, $matches);
var_dump($matches);
未经测试。