Search code examples
phphtmlgoogle-chromesafaritrim

Extra white spaces automatically disabled in PhP: why?


I was trying to use the trim() function on my $_POST variable for a form I just created, but noticed there was no use as the extra white spaces are automatically disabled.

I created a very simple PhP form (form.php) asking a name to the user. Then I have in my target.php (page where the data is processed) something like this:

<p>Hello <?php echo $_POST['nickname'];?>, how are you today?</p>

The fact is that even if the user enter as a name " Peter ", I see this in Safari and Chrome : "Hello Peter, how are you today?"... Without using the trim() function !

So here is my question : are the modern browser automatically trimming the end result?

Thank you in advance!


Solution

  • This is not an functionality but the browser is not showing the space I have tried with the below code

    $text = 'john ';
    $text[10] = 'doe';
    print_r($text);exit;
    

    You will see john d in the output even though there is a space at the end of john

    Try viewing the source and you will see something different