PHP: How to escape the URL params and path without encoding the Scheme and Host in URL:
Please notice* this url is just an example params might be named different than q and some urls might have path others might not, like the example below.
I get the url as follows:
http%3A%2F%2Fgoogle.com%2F?q=My%20Search%20Keyword Then I should converted to the following:
http://google.com/?q=My%20Search%20Keyword not:
http://google.com/?q=My Search Keyword is there an easy way for doing this, other than
- Url decoding the whole url, via "rawurldecode"
- "parse_url" to split it to scheme, domain, path, query
- Parse the query with parse_str and escape the values only.
- Rebuild the query string
- Rebuild the url back,
- All the steps above require checking for empty values too.
UPDATE
In more complicated case I get the URL like this:
http://www.someUrl.com/?redirect=http%3A%2F%2Fgoogle.com%2F%3Fq%3DMy%20Search%20Keyword%26hl%3Den Where I search for =http..... then I use this part to crawl it via Curl and get the http response code from this url, the problem is that I can't easily prepare the url which was sent ecnoded from the beginning without involving the complicated process I mentioned above.
is there an easier way of doing this ?
?q=if thats the only variable in the strong