Skip to content
Advertisement

PHP how to add data to spaces

I need to take data from a variable called $destination and add spaces between the info

So example:

echo $destination;

Would return: 123 Main St But I need it to return 123%20Main%20St

So I need a script that will take the data from $destination and add %20 in the spaces.

Advertisement

Answer

Use urlencode() to produce a string with percent encoding of special characters.

echo urlencode($destination);
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement