Search code examples
phpspecial-charactersdecodeencode

How to encode and decode / character with PHP


In my dynamically generated website sometimes parts of my URLs contain a / character:

Serena Williams/Venus Williams-Andrea Hlavackova/Lucie Hradecka

And, naturally, the URL returns a 404 error as the / sign is considered a folder so the URL doesn't exist.

What would be the PHP function to encode and later decode the string which contains a / character?


Solution

  • You can use PHP: urlencode to encode and its counterpart PHP: urldecode to decode:

    urlencode($stringinput)