anisgazig at gmail dot com ¶
10 months ago
If you want your file to be interpreted as php then your file must start and end with and everything outside of that is ignored by the php parser.
hellow..//normal test but ignred by php parser
Three types of tag are available in php
1.normal tag[]
2.short echo tag[]
3.short tag[]
short tag are bydefault available but can be disabled by short_open_tag = Off and also disabled bydefault if php will built with --disabe--short--tags[]
As short tag can be disabled so only use the normal and short echo tag.
If your file only have php code then do not use closing tag.
If you want to just print single text or something ,you should use shorthand version .
But if you want to process something, you should use normal tag.
If you embedded php with html and single line, do not need to use semicolon
but if you have multiple line, then use semicolon.
- Trang chủ
- Tham khảo
- Tag html
Định nghĩa và sử dụng
- Tag
là tag dùng để xuống hàng trong cùng đoạn văn, giống phím "Enter". - Tag
là tag trống, nó không có thẻ kết thúc.
Sự khác nhau giữa HTML và XHTML
Không cần kết thúc tag | Cần khoảng trắng và ký tự "/" để kết thúc tag |
Cấu trúc
Cần thiết phải có "khoảng trắng" và dấu "/" để chính xác trong tất cả các phiên bản HTML.
Ví dụ
Html viết:
Dòng text dài cần xuống hàng
Đã xuống hàng.
Hiển thị trình duyệt:
Dòng text dài cần xuống hàng
Đã xuống hàng.
Trình duyệt hỗ trợ
được hỗ trợ trong đa số các trình duyệt.
Thuộc tính
Cách sử dụng:
Thuộc tính tổng quát [xem thêm]
class | Tên class | class="section" | Tên class |
id | Tên id | id="layout" | Xác định tên id cho thành phần, mỗi thành phần chỉ có một id duy nhất [hoặc một id chỉ có trong một thành phần] trong một văn bản HTML |
style | Kiểu định dạng | style="color:red" | Xác định một định dạng cho một thành phần. |
title | Text | title="Đây là title" | Xác định thêm thông tin cho thành phần. |
[PHP 4, PHP 5, PHP 7, PHP 8]
nl2br — Inserts HTML line breaks before all newlines in a string
Description
nl2br[string $string
, bool $use_xhtml
= true
]: string
Parameters
string
The input string.
use_xhtml
Whether to use XHTML compatible line breaks or not.
Return Values
Returns the altered string.
Examples
Example #1 Using nl2br[]
Collette ¶
2 years ago
Let's say a form text field does contain:
test line number 1
test line number 2
To remove all the line breaks and split the input into an array:
$input_from_text_field = preg_replace['#[\r\n]#','',nl2br[$input_from_text_field,false]];
$lines = explode["
",$input_from_text_field];
$lines will now be an array where $lines[0] = "test line number 1" and so on.
buzanits at gmail dot com ¶
4 years ago
If you write code that is to run in browser AND on the shell, this function could be useful. It uses PHP_EOL or
depending on the platform it runs:
leo dot mauro dot desenv at gmail dot com ¶
6 years ago
I test empirically this function nl2br and nl2br2 [create by ngkongs at gmail dot com].
Both work nice with different ASCII chars for linebreak, but the function nl2br2 is faster than nl2br.
nl2br2 ~ 0.0000309944153 s
nl2br ~ 0.0011141300201 s
The function nl2br2:
Justinas M. ¶
6 years ago
This is example with "\R" regex token which matches any unicode newline character.
"u" flag treate strings as UTF-16. Which is optional, depending on your use case.
NOTE:
preg_replace versions are much slower than using str_replace version or built-in nl2br.
Check out pcre.backtrack_limit php.ini setting for information about PCRE limit. It's good to know.
# nl2br_str # nl2br_preg_R # nl2br_preg_rnnrSome PHP7 benchmarks:
# nl2br
## Time: 0.02895712852478 s
## Time: 0.027923107147217 s
## Time: 0.13350105285645 s
## Time: 0.14213299751282 s
chad at nobodyfamous dot ca ¶
5 years ago
I just spent a whole day trying to figure out why my textarea $_POST was not getting
tags added by nl2br[]. So for others
returns newlines as
and
so nl2br will miss them.
rather use and newlines will remain intact so nl2br will pick them up.
blacknine313 at gmail dot com ¶
14 years ago
After a recent post at the forums on Dev Shed, I noticed that it isn't mentioned, so I will mention it.
nl2br returns pure HTML, so it should be after PHP anti-HTML functions [ such as strip_tags and htmlspecialchars ].
darenschwenke at yahoo dot com ¶
8 years ago
This one works with br tags having attributes, in any case,
closed or not closed, and does not double linefeeds
I combine this with strip_tags[] for dead simple "contenteditable" fields allowing only text and linefeeds.
j dot mons54 at gmail dot com ¶
10 years ago
for bbcode :
hyponiq at gmail dot com ¶
15 years ago
On the contrary, mark at dreamjunky.comno-spam, this function is rightfully named. Allow me to explain. Although it does re-add the line break, it does so in an attempt to stay standards-compliant with the W3C recommendations for code format.
According to said recommendations, a new line character must follow a line break tag. In this situation, the new line is not removed, but a break tag is added for proper browser display where a paragraph isn't necessary or wanted.