lisovaccaro
lisovaccaro

Reputation: 33956

Encode URL with PHP, show + instead of %20

I want to encode the post's title so I can add it to my URLs. The problem is that urlencode() gives me an URL such as:

Title:

Samsung Nexus S + Hard Case

URL:

Samsung%20Nexus%20S%20+%20Hard%20Case

And I want one more friendly like:

Samsung+Nexus+S+Hard+Case

I don't know what should happen to the '+' symbol. How can I do this?

Upvotes: 0

Views: 1506

Answers (1)

Gio Borje
Gio Borje

Reputation: 21104

Replace the spaces with + since %20 is the url encoding of a space. Here's an example of space replacement in PHP:

str_replace(' ', '+', $url_encoded_string);

Upvotes: 1

Related Questions