我试图在curl操作后将regex与以下html响应匹配,如果它显示
Results: Displaying 1 of 1 entries
那么我有以下代码设置
$pos = strpos($response, 'Results: Displaying 1 of 1 entries');
和我使用if
($pos !== false) '来做事情
然而,我还需要匹配条件,我需要微调搜索参数,如果它将返回一组结果(多于1)
比如Results: Displaying 1 of X entries
x大于1
什么正则表达式可以与strpos一起使用来匹配这个条件
您必须使用preg_match(): http://mx1.php.net/preg_match
int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )
你的正则表达式可能是:
Results: Displaying 1 of ([0-9]+) entries
要检查数字是否大于1,必须比较第一个捕获的组,该组可以在数组&$matches[1]中找到(第三个参数,请参阅php文档)。