1
tianxiacangshen OP 已经找到方法:
function besturl($str, $replace=array(), $delimiter='-') { if( !empty($replace) ) { $str = str_replace((array)$replace, ' ', $str); } $clean = preg_replace(array('/Ä/', '/Ö/', '/Ü/', '/ä/', '/ö/', '/ü/'), array('Ae', 'Oe', 'Ue', 'ae', 'oe', 'ue'), $str); $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $clean); $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean); $clean = strtolower(trim($clean, '-')); $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean); return $clean; } 来源: https://stackoverflow.com/questions/4783802/converting-string-into-web-safe-uri |
2
nifury 2017-10-21 22:36:59 +08:00
urlencode?
|
3
feiyuanqiu 2017-10-21 22:46:53 +08:00 1
|
4
autoxbc 2017-10-21 22:53:47 +08:00
javascript
'Decision making, after the fact'.match(/\w+/g).join('-') // "Decision-making-after-the-fact" |
5
Sikoay 2017-10-22 00:14:44 +08:00 via Android
看文档 urlencode
|
6
oh 2017-10-22 02:00:48 +08:00
urlencode 就是解决这个问题的,实在不行还可以 base64 啊,逐字替换总会有遗漏的,encode 才是王道
|
7
tianxiacangshen OP |
8
shiji 2017-10-22 10:19:29 +08:00
@tianxiacangshen 搜索引擎收录的时候也一样会 urldecode 的。 不利于 SEO 有什么依据么?
|
9
tianxiacangshen OP @shiji 这个很简单,比如写一篇英文文章,标题是 “ Find Website Traffic, Statistics, and Analytics ”
如果使用 urlencode 转化为 url 是:Find+Website+Traffic%2C+Statistics%2C+and+Analytics 如果使用上面写的函数则是:find-website-traffic-statistics-and-analytics 对用户体验,和对搜索引擎的友好度不言自明 |