我为我的故事 URL 创建了一个带有破折号的 slug,例如:
使用 slug 而不是 ID 来获取记录 https://stackoverflow.com/questions/482636/fetching-records-with-slug-instead-of-id
这是我创建 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);
但当有?
or .
在URL中,则无法显示!
有什么帮助可以找回原始网址吗?!