微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

想象一下包含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);

原文地址:https://www.jb51.cc/php/138875.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐