Hướng dẫn nl2br python - trăn nl2br

Hàm nl2br() sẽ thêm các thẻ xuống dòng (
)  vào trước khi bắt đầu dòng mới trong chuỗi ( \r, \n, \n, \r, \n and \r).

Hướng dẫn nl2br python - trăn nl2br

Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức.freetuts.net, không được copy dưới mọi hình thức.

Cú pháp

Cú pháp: nl2br( $str, $is_xhtml); nl2br( $str, $is_xhtml);

Trong đó::

  • $str là chuỗi cần thêm các thẻ
    .
  • freetuts.net PHP functionn
    freetuts.net
    PHP functionn
    0 là tham số không bắt buộc mặc định là TRUE, quy định xem có xuống dòng tương thích với XHTML hay không.TRUE, quy định xem có xuống dòng tương thích với XHTML hay không.

Ví dụ

Code

echo "freetuts.net\n PHP functionn";
echo "
"; echo nl2br("freetuts.net\n PHP functionn");

Kết quả

freetuts.net PHP functionn
freetuts.net
PHP functionn

Code

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);

Kết quả

Tham khảo: php.net

Bài viết này được đăng tại [free tuts .net]

❮ Tham chiếu chuỗi PHP

Thí dụ

Chèn ngắt dòng nơi xuất hiện dòng mới (\ n) trong chuỗi:
echo nl2br("One line.\nAnother line.");
?>

Đầu ra trình duyệt của đoạn mã trên sẽ là:

Đầu ra trình duyệt của đoạn mã trên sẽ là:
Another line.

One line. Another line.

Đầu ra trình duyệt của đoạn mã trên sẽ là:
Another line.


One line. Another line.

Đầu ra HTML của đoạn mã trên sẽ là (Xem Nguồn):


Cú pháp

Định nghĩa và Cách sử dụng

Hàm nl2br () chèn các ngắt dòng HTML ( hoặc ) vào trước mỗi dòng mới (\ n) trong một chuỗi.Giá trị tham số
ParameterDescription
string Required. Specifies the string to check
  • xhtml 
  • Optional. A boolean value that indicates whether or not to use XHTML compatible line breaks:


TRUE- Default. Inserts

FALSE - Inserts Chi tiết kỹ thuật
Giá trị trả lại:4+
Changelog:Trả về chuỗi đã chuyển đổixhtml đã được thêm vào PHP 5.3.
Trước PHP 4.0.5, nó đã chèn
.
Sau PHP 4.0.5, nó sẽ chèn
.


Phiên bản PHP:

❮ Tham chiếu chuỗi PHP

Thí dụ

Chèn ngắt dòng nơi xuất hiện dòng mới (\ n) trong chuỗi:
echo nl2br("One line.\nAnother line.",false);
?>

Đầu ra trình duyệt của đoạn mã trên sẽ là:

Đầu ra trình duyệt của đoạn mã trên sẽ là:
Another line.

One line. Another line.

Đầu ra trình duyệt của đoạn mã trên sẽ là:
Another line.


Bài viết này được đăng tại [free tuts .net]


❮ Tham chiếu chuỗi PHP

Thí dụInserts HTML line breaks before all newlines in a string

Giá trị tham số

Parameter(string

freetuts.net PHP functionn
freetuts.net
PHP functionn
1, bool
freetuts.net PHP functionn
freetuts.net
PHP functionn
2 =
freetuts.net PHP functionn
freetuts.net
PHP functionn
3
): string

Description

string

Required. Specifies the string to check

xhtml 

Optional. A boolean value that indicates whether or not to use XHTML compatible line breaks:

TRUE- Default. Inserts

FALSE - Inserts

Chi tiết kỹ thuật

Giá trị trả lại:nl2br()

freetuts.net PHP functionn
freetuts.net
PHP functionn
6

Trả về chuỗi đã chuyển đổi

Phiên bản PHP:

freetuts.net PHP functionn
freetuts.net
PHP functionn
8

Trả về chuỗi đã chuyển đổi

Welcome
This is my HTML document

Phiên bản PHP:

freetuts.net PHP functionn
freetuts.net
PHP functionn
9

Trả về chuỗi đã chuyển đổi

This
is
a
string

Phiên bản PHP:

  • Tham số xhtml đã được thêm vào PHP 5.3. Trước PHP 4.0.5, nó đã chèn . Sau PHP 4.0.5, nó sẽ chèn .
  • Các ví dụ khác
  • Chèn ngắt dòng khi xuất hiện dòng mới (\ n), sử dụng tham số xhtml:
  • str_replace() - Replace all occurrences of the search string with the replacement string

(PHP 4, PHP 5, PHP 7, PHP 8)

nl2br — Inserts HTML line breaks before all newlines in a string

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
0

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
1

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
2

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
3

nl2br(string

freetuts.net PHP functionn
freetuts.net
PHP functionn
1, bool
freetuts.net PHP functionn
freetuts.net
PHP functionn
2 =
freetuts.net PHP functionn
freetuts.net
PHP functionn
3): string

Parameters

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
4

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
5

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
6

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
3

freetuts.net PHP functionn
freetuts.net
PHP functionn
4

The input string.

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
8

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
9

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
3

freetuts.net PHP functionn
freetuts.net
PHP functionn
5

Whether to use XHTML compatible line breaks or not.

Welcome
This is my HTML document
1

Return Values

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
3

Returns the altered string.

Examples

Welcome
This is my HTML document
4

Welcome
This is my HTML document
5

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
3

Example #1 Using nl2br()

The above example will output:

Welcome
This is my HTML document
7

Welcome
This is my HTML document
8

Welcome
This is my HTML document
9

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
3

Example #2 Generating valid HTML markup using the

freetuts.net PHP functionn
freetuts.net
PHP functionn
5 parameter

Example #3 Various newline separators

This
is
a
string
1

This
is
a
string
2

This
is
a
string
3

This
is
a
string
4

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
3

See Also

Example #3 Various newline separators

See Also

This
is
a
string
7

This
is
a
string
8

This
is
a
string
9

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
3

htmlspecialchars() - Convert special characters to HTML entities

htmlentities() - Convert all applicable characters to HTML entities

nl2br()1

nl2br()2

nl2br()3

nl2br()4

wordwrap() - Wraps a string to a given number of characters

str_replace() - Replace all occurrences of the search string with the replacement string

nl2br()5

nl2br()6

nl2br()7

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
3

CGameProgrammer at gmail dot com ¶

str_replace() - Replace all occurrences of the search string with the replacement string

nl2br()9


0


1


2


3

CGameProgrammer at gmail dot com ¶

17 years ago


4


5


6

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
3

ngkongs at gmail dot com ¶

15 years ago


8


9

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
3

N/A ¶

Whether to use XHTML compatible line breaks or not.

nl2br( $str, $is_xhtml)1

nl2br( $str, $is_xhtml)2

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
3

Return Values

Returns the altered string.

Examples

nl2br( $str, $is_xhtml)5

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
3

Example #1 Using nl2br()

Parameters

nl2br( $str, $is_xhtml)7

nl2br( $str, $is_xhtml)8

$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
3