Discuz!X2.5的SEO标题设置不支持空格解决方法

在用discuz程序,之前就发现标题不支持空格了,看起来总觉得有点太紧了,在找discuz门户相关文章的代码的时候发现了一篇文章《Discuz!X2.5的SEO标题设置不支持空格解决方法》,于是拿过来记下来。

修改文件位置:
source\class\helper\helper_seo.php文件第49行附近的如下代码:

1
2
3
4
5
public static function strreplace_strip_split($searchs, $replaces, $str) {
$searchspace = array('((\s*\-\s*)+)', '((\s*\,\s*)+)', '((\s*\|\s*)+)', '((\s*\t\s*)+)', '((\s*_\s*)+)');
$replacespace = array('-', ',', '|', ' ', '_');
return trim(preg_replace($searchspace, $replacespace, str_replace($searchs, $replaces, $str)), ' ,-|_');
}

修改之前一定先备份,防止出错。修改后的代码为:

1
2
3
4
5
public static function strreplace_strip_split($searchs, $replaces, $str) {
$searchspace = array('(((\s)*\-(\s)*)+)', '(((\s)*\,(\s)*)+)', '(((\s)*\|(\s)*)+)', '(((\s)*\t(\s)*)+)', '(((\s)*_(\s)*)+)');
$replacespace = array('$3-$3', '$3,$3', '$3|$3', '$3 $3', '$3_$3');
return trim(preg_replace($searchspace, $replacespace, str_replace($searchs, $replaces, $str)), ' ,-|_');
}

Leave a Reply

You must be logged in to post a comment.

RSS feed for comments on this post. TrackBack URL