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