我想要http://mysite.com/id255/到http://mysite.com/gora-beach-inn/.
我的php看起来像:
$result = mysql_query("
SELECT id, header
FROM Article
");
while($data = mysql_fetch_assoc($result)){
mysql_query("
UPDATE Article
SET seo = '".MakeSeo($data['header'])."'
WHERE datum = '".$data['datum']."'
");
}
//Convert: "åäö" to "aao", "space" to "-", "!?" to "nothing", and all to lower case.
function MakeSeo($string)
{
???
}
Run Code Online (Sandbox Code Playgroud)
请帮我使用MakeSoe功能.
我使用moderewrite,所以我只需要帮助来生成url,所以我可以将它们保存在我的数据库中.
只是回答你的要求..在这里你去..
function makeSeo($text, $limit=75)
{
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
// trim
$text = trim($text, '-');
// lowercase
$text = strtolower($text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
if(strlen($text) > 70) {
$text = substr($text, 0, 70);
}
if (empty($text))
{
//return 'n-a';
return time();
}
return $text;
}
Run Code Online (Sandbox Code Playgroud)
您可以添加更多过滤器来清理网址,也可以添加更多内容以使该网址独一无二.
注意:我不是说将数据库添加到数据库是最好的方法.您可以使用其他技术实现相同类型的功能,例如mod_rewrite.