开发者

How can I reuse the escaped value of a query string in PHP?

开发者 https://www.devze.com 2023-01-29 12:13 出处:网络
I\'d like to reuse a multiple-term search query with + for escaping spaces. $_SERVER[\'QUERY_STRING\'] results in

I'd like to reuse a multiple-term search query with + for escaping spaces.

$_SERVER['QUERY_STRING'] results in

q=my+search+term 

while $_GET['q'] 开发者_StackOverflow中文版results in

my search term

How can I get

my+search+term

does it have to be regex?


urlencode($_GET['q']);


$q = str_replace(' ', '+', $_GET['q'])

or

$q = urlencode($_GET['q']);


No, you can use str_replace:

$str = str_replace(' ', '+', $str);

but if there are more special characters, urlencode is the better choice:

$str = urlencode($str);


$clean = urldecode($_SERVER['QUERY_STRING']);

http://www.php.net/manual/fr/function.urldecode.php

0

精彩评论

暂无评论...
验证码 换一张
取 消