本文介绍了如何在带有urlenocde的URL中用连字符(-)替换+的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在数据库中用空格存储了产品名称.例如Bike 86,洗衣机等.
使用urlencode后,URL进入浏览器,如下所示
I have stored the product names in database with spaces. For example Bike 86, Washing Machine etc.
After using urlencode URL comes to browser as below
http://www.example.com/product.php?productname=Washing+Machine
但我想得到这样的
But I want to get it such like
http://www.example.com/prodcut.php?productname=Washing-Machine
如何更改将空格编码为连字符(-)而不是"+"符号的urlencode函数.
如果urlencode无法实现,那我该怎么办.
注意:请给我一些其他解决方案,而不是str_replace();
How can I change the urlencode function that it encode the space into hyphen(-) not into "+" sign.
If it is not possible with urlencode then how can I do that.
Note: Please give me some other solution rather than str_replace();
推荐答案
RewriteEngine on
# Replace the minus character in incoming URLs with a space.
RewriteRule ^([^-]*)-([^-]*-.*)
这篇关于如何在带有urlenocde的URL中用连字符(-)替换+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!