Search code examples
phpurlurl-encoding

How to deal with question mark in url in php single entry website


I'm dealing with two question marks in a single entry website.

I'm trying to use urlencode to handle it. The original URL:

'search.php?query='.quote_replace(addmarks($search_results['did_you_mean'])).'&search=1'

I want to use it in the single entry website:

'index.php?page='.urlencode('search?query='.quote_replace(addmarks($search_results['did_you_mean'])).'&search=1')

It doesn't work, and I don't know if I must use urldecode and where I can use it also.


Solution

  • Why not just rewrite it to become

    index.php?page=search&query=...
    

    mod_rewrite will do this for you if you use the [QSA] (query string append) flag.

    http://wiki.apache.org/httpd/RewriteQueryString