我用破折号为我的故事 URL 制作了一个 slug,例如:
这是我创建 slug 的代码:
function Slugit($title) {
$title = strip_tags($title);
// Preserve escaped octets.
$title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
// Remove percent signs that are not part of an octet.
$title = str_replace('%', '', $title);
// Restore octets.
$title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
$title = remove_accents($title);
if (seems_utf8($title)) {
if (function_exists('mb_strtolower')) {
$title = mb_strtolower($title, 'UTF-8');
}
$title = utf8_uri_encode($title, 500);
}
$title = strtolower($title);
$title = preg_replace('/&.+?;/', '', $title); // kill entities
$title = str_replace('.', '-', $title);
$title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
$title = preg_replace('/\s+/', '-', $title);
$title = preg_replace('|-+|', '-', $title);
$title = trim($title, '-');
return $title;
}
如您所见,到这里为止,一切都很好。但是当我点击链接时,它无法打开并找到我的数据库,因为它以正常方式保存并且没有破折号。
所以我写了一些东西来删除破折号:
$string = str_replace('-', ' ', $string);
但是当URL中有?
或.
时,则无法显示!
有什么帮助找回原来的网址吗?!