Php 修改preg replace以清洁所有标志
我正在尝试使用此功能获取烫发链接:Php 修改preg replace以清洁所有标志,php,preg-replace,preg-match,Php,Preg Replace,Preg Match,我正在尝试使用此功能获取烫发链接: // Generates Permalink function gen_permalink($title) { $permalink=string_limit_words($title, 9); if(!mb_check_encoding($permalink,"UTF-8")) { $permalink=preg_replace("/[^a-z0-9\s]/i", "", $permalink);
// Generates Permalink
function gen_permalink($title)
{
$permalink=string_limit_words($title, 9);
if(!mb_check_encoding($permalink,"UTF-8"))
{
$permalink=preg_replace("/[^a-z0-9\s]/i", "", $permalink);
$permalink=trim(preg_replace("/\s\s+/", " ", $permalink));
$permalink=strtolower(str_replace(" ","-",$permalink));
}
else
{
$permalink=trim($title);
$permalink=str_replace(" ","-",$permalink);
}
$final = $permalink;
$count = 1;
while(already_exists($final))
{
$final = $permalink . "-" . $count;
$count++;
}
return $final;
但是我没法做那件事
发出
!!太好了
有趣的
大宗报价
是
!!真有趣
我正试图得到
真有趣
如果你只是想从
!真有趣代码>到太有趣了
您可以在返回之前执行以下操作:
$final = strtolower(preg_replace('/[^0-9a-zA-Z-]/','',$final));
它删除了除字母数字或符号以外的所有字符-
,并使所有字符都小写。为什么要重新发明轮子?有10亿个小型图书馆可以做到这一点。是一个比您的更小的版本,可以与UTF-8配合使用。另一方面,它也包含一个很好的函数。干得好,先生@谢谢。祝你的程序好运,或者不管你打算如何使用它。