想象一下包含UTF-8中几个单词的任何给定语言(英语,阿拉伯语,日语等)的页面标题字符串.例:
$stringRAW = "Blues & μπλουζ Bliss's ブルース Schön";
现在,这实际上需要转换为该页面的URL的有效部分:
$stringURL = "blues-μπλουζ-bliss-ブルース-schön"
just check out this link
这也适用于我的服务器!
Q1. What characters are allowed as valid URL these days? I remember having seen whol arabic strings sitting on the browser and i tested it on my apache 2 and all worked fine.
我猜它必须成为:$stringURL =“blues-blows-bliss-black”
Q2. What existing PHP functions do you know that encode/convert these UTF-8 strings correctly for URL ripping them off of any invalid chars?
我至少猜到了:
1.空格应转换成破折号 –
2.删除无效字符?他们是谁? @和’&’?
3.将所有字母转换为小写(或者是在网址中有效的capitcal字母?)
谢谢:非常感谢您的建议!
我会用:
$stringURL = str_replace(' ','-',$stringURL); // Converts spaces to dashes $stringURL = urlencode($stringURL);