我有一个名为2011-08-21-filename.php
我想提取日期和标题,因此永久链接将类似于/2011/08/21/filename
答案 0 :(得分:1)
$filename = "2011-08-21-filename.php";
preg_match('/(\d{4})-(\d{2})-(\d{2})-(\w*).php/', $filename, $matches);
$path = implode("/", array_slice($matches, 1)); // => string(19) "2011/08/21/filename"
答案 1 :(得分:-1)
$filename = str_replace(".php", "", preg_replace("/[0-9-]/", "", $string));
$directory = $dir.$filename;
快速解决方案,对不起,我对正则表达式不是很了解