-1

I've been working my way through W3Schools' PHP course and I've become flummoxed by something in one of the lessons -

http://www.w3schools.com/php/php_form_complete.asp

The form is filled using globals which are assigned after the user hits 'submit', the same globals are then echoed in the PHP block at the end of the script.

Here's my modification which specifies default values for the globals to avoid the need to fill in the form and hit submit -

phpfiddle link to my modification

What's confused me is that the comment box is -

I've   no<br>   comment

but when it's echoed by PHP the spaces are stripped and the output is -

I've no
comment

Echoing the var_dump of $comment gives -

string(23) "I've no
comment" 

Both the comment box and the echo statement use the same source, $comment, but the format of the string is different. Why is that? Can someone please explain this discrepancy to me.

fourjays
  • 61
  • 9

1 Answers1

2

By default the output of a PHP program (when launched via a web server) starts with Content-Type: text/html.

The output is treated as HTML source code.

<br> is the element that creates a line break in HTML and, in HTML, one or more whitespace characters is collapsed into a single space.

Related:

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335