Alexander Fuchs
Alexander Fuchs

Reputation: 1358

PHP encode/decode string only numbers and characters

I know about the PHP function encode() and decode(), they work well for me, but I want to pass the encoded string inside an url, but encode does return special chars like "=" "," "'" etc....

This does obviously break my script, what would be the best way to encode a string and get only numbers and characters?

Should I use a special hash?

Upvotes: 2

Views: 2870

Answers (2)

user1438038
user1438038

Reputation: 6079

There is also a urlencode() and urldecode() method that respects special characters.

Furthermore, rawurlencode() and rawurldecode() are provided to encode according to RFC-3986. This will return a string in which all non-alphanumeric characters have been replaced with a percent (%) sign followed by two hexadecimal digits.

Upvotes: 4

Dakkaron
Dakkaron

Reputation: 6276

Try urlencode()

This should encode the encoded string in a way that you can safely pass it in an url.

Upvotes: 2

Related Questions