这是一个自定义功能.此时,此函数将获取默认目录中的所有文件,删除".php"并列出它们.
问题是我只想从具有起始前缀"tpl-"的目录中获取文件示例:tpl-login-page.php
/* Get template name of the file */
function get_template_name (){
$files = preg_grep('~\.(php)$~', scandir(admin . "templates/default/"));
foreach($files as $file){
$file = str_replace('.php','',$file);
echo $file . "<br/>";
}
}
Run Code Online (Sandbox Code Playgroud) 我在放置的功能很少,但是没有按照我想要的方式工作.
根据帖子标题,即时自动创建slug.
示例:如果帖子标题是"测试",那么slug将是"test"
我的问题是,如果他们重复输入帖子标题"测试",这意味着slug也会被复制.出于这个原因,我已经创建了2个函数来为我处理这个问题.
此函数检查数据库中是否存在slug
function slug_exist($x){
global $db;
$sql = "SELECT post_name FROM posts WHERE post_name=\"$x\"";
$query = $db->select($sql);
if($db->num_rows() > 0){
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
如果slug确实存在于数据库中,那么我使用这个函数给slug一个唯一的名字
if(slug_exist($slug)){
$rand = rand(10,50);
$slug = $slug."-".$rand;
return $slug;
}
Run Code Online (Sandbox Code Playgroud)
那么当slug将获得独特的slug名称时,它就像 Example: test-244
我希望slug是按数字顺序而不是随机顺序.
**Example:**
Post Title is "Test"
Slug is "test-1"
Post Title is "Test"
Slug is "test-2"
Post Title is "Test"
Slug is "test-3"
Run Code Online (Sandbox Code Playgroud)
这是我知道如何详细解释的唯一方式,如果您不确定要采取什么,请告诉我.谢谢!
我正在使用XAMPP,我收到了这个错误
Fatal error: Cannot redeclare example() (previously declared in
Run Code Online (Sandbox Code Playgroud)
我理解这个错误,这意味着该函数已在其他地方声明.
在我的www.example.com/cores/functions.php中,我正在声明这个功能
function example(){
$site_name = "Example CMS";
return $site_name;
}
Run Code Online (Sandbox Code Playgroud)
该功能将执行什么操作,它将保留默认的示例CMS.但是,如果有人宣称在同一个函数www.example.com/functions.php,那么系统应该皮卡这是在www.example.com/functions.php,不应该在挑www.example.com/cores/functions .PHP
在我的www.example.com/functions.php中
function example(){
$site_name = "My CMS";
return $site_name;
}
Run Code Online (Sandbox Code Playgroud)
那可能吗?