|
因为欧洲 字符中有很多特殊字符(非英文)如 上面带一撇的e:é 等等(地址栏不完全支持,就像IE7才支持中文一样),CI自己的url_title 的时候,把这些字符全部去掉了,严重影响了 google的搜索,嘿嘿,所以,我们必须把他们替换成一般浏览器 地址栏支持的字符。
1. 在application/helper下创建 MY_url_helper.php
2.复制 CI库中的 url_title() 函数 到上面的文件。(包括if (! function_exists('url_title')) 正个if)
3.添加2 个替换数组(关键,虽然不理解,从公司法国技术部小伙子那问到的)
PHP复制代码 $str = strtr($str,"\xA1\xAA\xBA\xBF\xC0\xC1\xC2\xC3\xC5\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD\xE0\xE1\xE2\xE3\xE5\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8\xF9\xFA\xFB\xFD\xFF","!ao?AAAAACEEEEIIIIDNOOOOOUUUYaaaaaceeeeiiiidnooooouuuyy");
$str = strtr($str, array("\xC4"=>"Ae", "\xC6"=>"AE", "\xD6"=>"Oe", "\xDC"=>"Ue", "\xDE"=>"TH", "\xDF"=>"ss", "\xE4"=>"ae", "\xE6"=>"ae", "\xF6"=>"oe", "\xFC"=>"ue", "\xFE"=>"th"));
复制代码 OK.完成。application/helper/MY_url_helper.php正个文件如下PHP复制代码
<?php
// url_title function with muti-language by lony.
if (! function_exists('url_title'))
{
function url_title ($str, $separator = 'dash')
{
$str = strtr($str,"\xA1\xAA\xBA\xBF\xC0\xC1\xC2\xC3\xC5\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD\xE0\xE1\xE2\xE3\xE5\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8\xF9\xFA\xFB\xFD\xFF","!ao?AAAAACEEEEIIIIDNOOOOOUUUYaaaaaceeeeiiiidnooooouuuyy");
$str = strtr($str, array("\xC4"=>"Ae", "\xC6"=>"AE", "\xD6"=>"Oe", "\xDC"=>"Ue", "\xDE"=>"TH", "\xDF"=>"ss", "\xE4"=>"ae", "\xE6"=>"ae", "\xF6"=>"oe", "\xFC"=>"ue", "\xFE"=>"th"));
if ($separator == 'dash')
{
$search = '_';
$replace = '-';
}
else
{
$search = '-';
$replace = '_';
}
$trans = array(
$search => $replace,
"\s+" => $replace,
"[^a-z0-9".$replace."]" => '',
$replace."+" => $replace,
$replace."$" => '',
"^".$replace => ''
);
$str = strip_tags(strtolower($str));
foreach ($trans as $key => $val)
{
$str = preg_replace("#".$key."#", $val, $str);
}
return trim(stripslashes($str));
}
}
?> 复制代码
上次发了一次,好像数据丢咯~~再不上~~ |
评分
-
查看全部评分
|