Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.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 使用正则表达式从字符串中提取创建日期、上次修改日期和方法名称_Php_Regex - Fatal编程技术网

Php 使用正则表达式从字符串中提取创建日期、上次修改日期和方法名称

Php 使用正则表达式从字符串中提取创建日期、上次修改日期和方法名称,php,regex,Php,Regex,下面是存储在名为 Website.php 基本上,当用户(在本例中是AdamInChains)在其网站上创建一个新页面时,一个新方法(声明为输入页面名称)被添加到类中,日期被添加到该方法的文档注释中 到目前为止,我只能提取方法名称(见下面的代码),但在其他任务中没有成功 有人吗?这里有一个正则表达式,您可以使用它: (?<creationDate>\d{2}\.\d{2}\.\d{4}\s\d{2}:\d{2}:\d{2})\screation\sdate[^\Z]*?(?<m

下面是存储在名为 Website.php

基本上,当用户(在本例中是AdamInChains)在其网站上创建一个新页面时,一个新方法(声明为输入页面名称)被添加到类中,日期被添加到该方法的文档注释中

到目前为止,我只能提取方法名称(见下面的代码),但在其他任务中没有成功


有人吗?

这里有一个正则表达式,您可以使用它:

(?<creationDate>\d{2}\.\d{2}\.\d{4}\s\d{2}:\d{2}:\d{2})\screation\sdate[^\Z]*?(?<modifiedDate>\d{2}\.\d{2}\.\d{4}\s\d{2}:\d{2}:\d{2})\slast\smodified\sdate[^\Z]*?public\sfunction\s(?<methodName>[^\(\s]+)
$array = [
    // method name
    "index" => [
        "creation_date"=>"02.14.2019 14:01:52",
        "last_modified_date"=>"02.14.2019 13:28:23"
    ]
];
// regex pattern
$re = '/public function.(\w{0,})/m';
// file 'Website.php'
$str = file_get_contents('Website.php');

preg_match_all($re, $str, $matches);

// Print the entire match result
var_dump($matches);
(?<creationDate>\d{2}\.\d{2}\.\d{4}\s\d{2}:\d{2}:\d{2})\screation\sdate[^\Z]*?(?<modifiedDate>\d{2}\.\d{2}\.\d{4}\s\d{2}:\d{2}:\d{2})\slast\smodified\sdate[^\Z]*?public\sfunction\s(?<methodName>[^\(\s]+)