PHP URL 中的减号(rawurlencode 与 urlencode)
我尝试过使用 rawurlencode 和 urlencode,两者都给我“&”和另一个“+”。
我要问的是,是否有一个 PHP 函数可以在单词之间添加“-”,就像 Stack Overflow 上那样?
谢谢
I've tried using rawurlencode and urlencode, both give me "&" and the other "+".
What i'm asking is, is there a PHP function that puts "-" in between words, like on Stack Overflow?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果这就是您想要做的,您可以使用:
然后使用 urlencode 对其进行编码。 EG:
编辑
并根据PHP手册,它替换除 -_ 之外的所有非字母数字字符。百分号 (%) 后跟两个十六进制数字和编码为加号 (+) 的空格。
If thats all you're trying to do, you could just use:
And then use
urlencode
to encode it after that. E.G.:EDIT
And according to the PHP manual, it replaces
all non-alphanumeric characters except -_. with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs.
rawurlencode
和urlencode
用于使 URL 的格式正确。如果你想用破折号替换空格,你需要使用str_replace
:rawurlencode
andurlencode
are for making URL's the correct format. If you want to replace spaces for dashes you need to usestr_replace
:如果您只想将一类字符替换为另一类字符,请使用 str_replace< /a>
例如:
会做你想做的
urlencode 是非常具体的字符替换集,遵循 url 编码标准。
If you just want to replace a class of characters with another, use str_replace
For example:
would do what you want
urlencode is a very specific set of character replacements, which follow the standard for url encoding.
好的,正如前面提到的,
url_encode
与从文本生成 URL 无关,即使它们对 SEO 友好。通常这称为 slugify url。我想这通常就是您正在寻找的,对吧?这是这种方法的示例 http://sourcecookbook .com/en/recipes/8/function-to-slugify-strings-in-php
Okay, as mentioned
url_encode
is independent from making URLs from text ie to make them SEO-friendly. Usually this is called slugify an url. I guess this is generally what you're looking for, right?Here is an example of such a method http://sourcecookbook.com/en/recipes/8/function-to-slugify-strings-in-php