0

When I have URL like this

site.com/index.php?name=JON%20%20%20%20%20%20%20SMIT

and I print $_GET['name'] variable in index.php file, result is Jon Smit.

That is, queue spaces between JON and SMIT, are replaced on one space. why this happened?

0

3 Answers 3

2

HTML ignores extraneous whitespace, so no matter how many spaces you put in the name, when it is output in a browser, the browser will only show one space. You need to replace your spaces with   (non-breaking space) to ensure the browser displays them all.

Sign up to request clarification or add additional context in comments.

Comments

1

This should preserve the spaces:

print rawurldecode($_GET['name']);

This will print the extra spaces, however your browser may ignore the extra spaces. Documentation

Comments

1

How the special chars (like the space) is encodet in the URL is defined, look also Wiki. You can URL encode via urlencode and the inverse of that is urldecode

About the ONE Space only: Look into the source of the Page (i.e. the HTML-Code), in Firefox e.g. via Ctrl+U, there will be many more spaces. BUT: The browser only displays one of them. If you want to preserve them in the output, you could use something like

echo '<pre>' . $_GET['name'] . '</pre>';

OR

echo str_replace(' ', '&nbsp;', $_GET['name']);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.