PHP echo newline

 The PHP echo newline technique will use the HTML built-in newline tag, that is, the <br> tag. This newline tag means only one line at a time. If you want to change two lines, you need to use the <br> tag twice. , You can also use paragraph tags, that is, <p> tags to achieve the effect of changing two lines at a time. We will implement the <br> and <p> tags in the example for readers' reference. Through the concept of PHP echo html , you can easily echo newline tags, and all regular mainstream browsers support the effect of PHP echo newline tags.


PHP echo line break example 1. Only change a line <br> tag
<?php
echo'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'; //Web page encoding declaration  
echo'This is the first line<br>';
echo 'This is the second line<br>';
echo'<br>';  
echo'This is the fourth line';
?>
Example output
This is the first row
this is the second row

this is the fourth row
The first example simply uses the newline <br> tag. When the browser sees the <br> tag, it will automatically change to the next line, one line at a time, and so on, so if you want to change two lines, you must use two The second <br> tag, the example deliberately skips the third line and directly changes to the fourth line, which is done with the <br> tag twice.

It should be noted here that the echo wrap effect must use single quotes (") or double quotes ("") to wrap the entire string, including the <br> tag, so that PHP can smoothly output the newline tags as a string. The browser can understand it. For the usage of echo, please refer to the detailed introduction of PHP echo ".

PHP echo line break example 2: Paragraph <p> tag and line break <br> tag
<?php
echo'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'; //Web page encoding declaration  
echo'<p>This is the first paragraph<br> This is the second line of the first paragraph</p>';
echo'<p>This is the second paragraph<br>This is the second line of the second paragraph</p>';
?>
Example output

This is the first paragraph
This is the second line of the first paragraph

This is the second paragraph,
this is the second line of the second paragraph

The second example uses the <p> tag specially used to mark paragraphs. The usage of this <p> tag is different from the <br> tag. The <p> tag needs to use one set at a time, which is the beginning of the <p>,</p> At the end, the string wrapped in the middle is even a paragraph, and each group of <p></p> tags will automatically wrap to two lines. The effect is equivalent to two <br> tags.

The above two examples are commonly used PHP echo line breaks. If you simply want to change a line, then use <br>. If the purpose of line breaking is a paragraph, the <p> tag is more suitable, but this part There is no mandatory requirement, depending on the web designer's own plan.

Post a Comment

0 Comments