Skip to content
PHP Logo

How can PHP handle titles with spaces when passing them as parameters in a URL?

When passing titles with spaces as parameters in a URL, PHP will convert the spaces to "%20" which can make the URL look messy and less user-friendly. To handle titles with spaces, you can use PHP's urlencode() function to encode the title before passing it in the URL. This will convert the spaces to "%20" and ensure that the URL is properly formatted.

php
$title = "Hello World";
$encoded_title = urlencode($title);
echo "<a href='example.php?title=$encoded_title'>Link</a>";