SUN Jiangong
SUN Jiangong

Reputation: 5312

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.

Upvotes: 0

Views: 1246

Answers (3)

ivanjovanovic
ivanjovanovic

Reputation: 511

I would suggest you to change the logic of the server code to handle simpler query form. This way it is probably going to lead you nowhere in very near future.

Use

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

as your query format but do not overwrite it with mod_rewrite to your first wanted format just to satisfy your current application logic, but handle it with some better logic on the server side. Write some ifs and thens, switches and cases ... but do not try to put the logic of the application into your URLs. It will make you really awkward URLs and soon you'll see that there is no lot of space in that layer to handle all the logic you will need. :)

Upvotes: 0

ChronoFish
ChronoFish

Reputation: 3707

$_SERVER['QUERY_STRING'] will give you everything after the first "?" in a URL.

From here you can parse using "explode" or common sting functions.

Example:

http://xxx/info.php?test=1?test=2&test=3

$_SERVER['QUERY_STRING'] =>test=1?test=2&test=3

list($localURL, $remoteURL) = explode("?", $_SERVER['QUERY_STRING']);

$localURL => 'test=1'

$remoretURL =>'test=2&test=3'

Hope this helps

Upvotes: 0

Alex J
Alex J

Reputation: 10205

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

Upvotes: 1

Related Questions