加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 如何将一个漂亮的页面标题转换为有效的URL字符串?

发布时间:2020-12-13 13:50:08 所属栏目:PHP教程 来源:网络整理
导读:想象一下包含UTF-8中几个单词的任何给定语言(英语,阿拉伯语,日语等)的页面标题字符串.例: $stringRAW = "Blues μπλουζ Bliss's ブルース Sch?n"; 现在,这实际上需要转换为该页面的URL的有效部分: $stringURL = "blues-μπλουζ-bliss-ブルース-s
想象一下包含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);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读