wowpatrick
wowpatrick

Reputation: 5180

Create human readable URL search strings

I just implemented a search function into my program. If a search string is sent, the program dose this:

if (isset($_GET['s'])) {
    header('Location: /search/'.rawurlencode($_GET['s']));
    exit;
}

The only problem I have is that the resulting search string URL isn't really human readable, e.g. the search term is 500€ a lot of money results into is%20500€%20a%20lot%20of%20money. I would like to build a more human readable search URL, e.g. is+500€+a+lot+of+money.

Is there a simple way of doing this or do you have to encode the string manually, e.g. look for spaces, etc. and replace them.

Upvotes: 3

Views: 1135

Answers (1)

lonesomeday
lonesomeday

Reputation: 237845

Use urlencode instead of rawurlencode. This uses + for spaces rather than %20.

Upvotes: 10

Related Questions