Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php ReGex Help——提取单词旁边的数字_Php_Regex - Fatal编程技术网

Php ReGex Help——提取单词旁边的数字

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'; 在本例中,我希望将页面计数存储

使用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';
在本例中,我希望将页面计数存储为$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
)