Php ReGex Help——提取单词旁边的数字
使用PHP时,我需要知道如何获取短语Page count:旁边的数字。下面是输出的样子Php ReGex Help——提取单词旁边的数字,php,regex,Php,Regex,使用PHP时,我需要知道如何获取短语Page count:旁边的数字。下面是输出的样子 $string = 'Author: Microtest Windows Version 1.1 Creation time: 2016-02-12 02:51:00 Last modified by: Some Name Last modification time: 2016-02-12 15:51:00 Page count: 14 Word count: 5142'; 在本例中,我希望将页面计数存储
$string = 'Author: Microtest Windows Version 1.1
Creation time: 2016-02-12 02:51:00
Last modified by: Some Name
Last modification time: 2016-02-12 15:51:00
Page count: 14
Word count: 5142';
在本例中,我希望将页面计数存储为$page\u number。即
echo $page_number; --> 14
如何使用REGEX执行此操作?REGEX:/Page count:\s*\K\d+/
页数:\s*以匹配页数:0或更多空格
\K重置当前匹配
\d+用于抓取数字
页数:\d+。就是这样。echo$匹配项[0]@Styluss是,echo$匹配[0];给你你想要的。页数
<?php
$string = 'Author: Microtest Windows Version 1.1
Creation time: 2016-02-12 02:51:00
Last modified by: Some Name
Last modification time: 2016-02-12 15:51:00
Page count: 14
Word count: 5142';
preg_match("/Page count:\s*\K\d+/", $string,$matches);
print_r($matches);
Array
(
[0] => 14
)