I have been searching online with little success for a way to force php to output a newline after a closing php tag ?>
so that my HTML will be rendered as I see it before its parsed by PHP so that it will look neat and tidy when viewing the html source code for a page.
I want to stop it from removing the newline and causing the next line from wrapping up and therefore ruining the format of the page. Is there a specific php.ini
setting I can change to disable this behaviour?
All my code logic files have ?>
removed from the end of them so I wont need to worry about them injecting extra newlines which is why I believe PHP was coded to strip the trailing new lines.
Answer: Use the Newline Characters ' \n ' or ' \r\n ' You can use the PHP newline characters \n or \r\n to create a new line inside the source code. However, if you want the line breaks to be visible in the browser too, you can use the PHP nl2br() function which inserts HTML line breaks before all newlines in a string.
The tags tell the web server to treat everything inside the tags as PHP code to run. The code is very simple. It uses an in-build PHP function "echo" to display the text "Hello World ..." in the web page.
To recap, closing PHP tags (?>) are entirely optional if you're coding a PHP-only file and there's no intermingled HTML. Files containing single class definitions are good candidates. Omitting the closing tag has another benefit: it becomes impossible to accidentally add white space to the end of the file.
The closing tag of a block of PHP code automatically implies a semicolon; you do not need to have a semicolon terminating the last line of a PHP block. The closing tag for the block will include the immediately trailing newline if one is present. <?
Richard is saying this:
Hello <? ?> Jello
...after PHP-parsing becomes this:
Hello Jello
I just add an extra newline manually, like this:
Hello <? ?> Jello
...giving this:
Hello Jello
This is an old question, but to keep the new line, simply place a space after the closing tag.
Source: http://php.net/manual/en/language.basic-syntax.instruction-separation.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With