我有类似的东西
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”。
最佳答案
这个有效:
$t = preg_match('/Page [0-9]+ of ([0-9]+)/i', $page, $matches);
关于php - 正则表达式查找数字和括号之间的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14383821/