【发布时间】:2014-03-25 08:43:35
【问题描述】:
我正在使用下面的代码尝试转换为 slug,但由于某种原因它没有回显任何内容。我知道我遗漏了一些非常明显的东西。我不是在调用函数吗?
<?php
$string = "Can't You Convert This To A Slug?";
function clean($string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
echo $string;
}
?>
【问题讨论】:
-
什么是 slug 以及您要覆盖到 slug 中的 URL 在哪里?
-
@Shahar 在
WordPress的说法中,slug是特定帖子的URL key。 -
你永远不会调用该方法...在底部添加
clean($string);。