php replace %20
i curently try to make a search for my system using $_GET so when user copy the address link of results http://localhost/search?q=iphone%204
how to replce %20 to use + and for same time,when query the sql,it wil开发者_StackOverflow社区l search for 'iphone 4' not 'iphone+4' .
any idea?
thanks
To replace %20 with +
$url = str_replace("%20", "+", $url);
To change the plus into a space for your queries:
$url = urldecode($url);
Use urlencode
to encode. The decoding will happen automatically, you just need to read the value from $_GET
.
encode your "+" using "%2B". or use rawurldecode instead of urldecode. If that's not what you need than please supply some code so I can be more specific.
You don't need to decode it if you just use the $_GET
array: http://ca.php.net/manual/en/reserved.variables.get.php
If you use the link you mentioned, you can access the query using echo $_GET['q']
will result in iphone 4
, then you can use explode(' ', $_GET['q'])
which will result in array('iphone', '4')
.
精彩评论