Hướng dẫn are php tags case - thẻ php là trường hợp

Tất cả mọi thứ bên ngoài một cặp thẻ mở và đóng đều bị bỏ qua bởi trình phân tích cú pháp PHP cho phép các tệp PHP có nội dung hỗn hợp. Điều này cho phép PHP được nhúng trong các tài liệu HTML, ví dụ để tạo các mẫu.

This is going to be ignored by PHP and displayed by the browser.


echo 'While this is going to be parsed.'?>

This will also be ignored by PHP and displayed by the browser.

Điều này hoạt động như mong đợi, bởi vì khi trình thông dịch PHP nhấn? Trong trường hợp đó, thông dịch viên sẽ xác định kết quả của điều kiện trước khi đưa ra quyết định về những gì cần bỏ qua. Xem ví dụ tiếp theo.

Sử dụng các cấu trúc với các điều kiện

Ví dụ #1 Escaping nâng cao bằng cách sử dụng các điều kiện

if ($expression == true): ?>
  This will show if the expression is true.
else: ?>
  Otherwise this will show.
endif; ?>

Trong ví dụ này, PHP sẽ bỏ qua các khối mà điều kiện không được đáp ứng, mặc dù chúng nằm ngoài các thẻ mở/đóng PHP; PHP bỏ qua chúng theo điều kiện vì trình thông dịch PHP sẽ nhảy qua các khối có trong một điều kiện không được đáp ứng.

Để xuất ra các khối văn bản lớn, việc bỏ chế độ phân tích cú pháp PHP thường hiệu quả hơn so với việc gửi tất cả văn bản qua Echo hoặc in.echo or print.

Ghi chú::

Nếu PHP được nhúng trong XML hoặc XHTML, PHP bình thường phải được sử dụng để vẫn tuân thủ các tiêu chuẩn.

Quickfur tại Quickfur dot ath dot cx ¶

12 năm trước

When the documentation says that the PHP parser ignores everything outside the ... ?> tags, it means literally EVERYTHING. Including things you normally wouldn't consider "valid", such as the following:


if ($highlight): ?> class="highlight"endif;?>>This is a paragraph.


Notice how the PHP code is embedded in the middle of an HTML opening tag. The PHP parser doesn't care that it's in the middle of an opening tag, and doesn't require that it be closed. It also doesn't care that after the closing ?> tag is the end of the HTML opening tag. So, if $highlight is true, then the output will be:


This is a paragraph.


Otherwise, it will be:


This is a paragraph.


Using this method, you can have HTML tags with optional attributes, depending on some PHP condition. Extremely flexible and useful!

if ($expression == true): ?>
  This will show if the expression is true.
else: ?>
  Otherwise this will show.
endif; ?>
0

Ravenswd tại Gmail Dot Com ¶

13 năm trước

if ($expression == true): ?>
  This will show if the expression is true.
else: ?>
  Otherwise this will show.
endif; ?>
1

if ($expression == true): ?>
  This will show if the expression is true.
else: ?>
  Otherwise this will show.
endif; ?>
2

if ($expression == true): ?>
  This will show if the expression is true.
else: ?>
  Otherwise this will show.
endif; ?>
3

if ($expression == true): ?>
  This will show if the expression is true.
else: ?>
  Otherwise this will show.
endif; ?>
4

if ($expression == true): ?>
  This will show if the expression is true.
else: ?>
  Otherwise this will show.
endif; ?>
5

if ($expression == true): ?>
  This will show if the expression is true.
else: ?>
  Otherwise this will show.
endif; ?>
6

if ($expression == true): ?>
  This will show if the expression is true.
else: ?>
  Otherwise this will show.
endif; ?>
0

snor_007 tại hotmail dot com

12 năm trước

if ($expression == true): ?>
  This will show if the expression is true.
else: ?>
  Otherwise this will show.
endif; ?>
8

if ($expression == true): ?>
  This will show if the expression is true.
else: ?>
  Otherwise this will show.
endif; ?>
9

0

1

2

if ($expression == true): ?>
  This will show if the expression is true.
else: ?>
  Otherwise this will show.
endif; ?>
0

Ravenswd tại Gmail Dot Com ¶

13 năm trước

4

5

6

if ($expression == true): ?>
  This will show if the expression is true.
else: ?>
  Otherwise this will show.
endif; ?>
0

snor_007 tại hotmail dot com

sgurukrupa tại gmail dot com ¶

8

8 năm trước

Anisgazig tại Gmail Dot Com ¶

9

When the documentation says that the PHP parser ignores everything outside the ... ?> tags, it means literally EVERYTHING. Including things you normally wouldn't consider "valid", such as the following:0

if ($expression == true): ?>
  This will show if the expression is true.
else: ?>
  Otherwise this will show.
endif; ?>
0

3 năm trước

Mike tại Clove Dot Com ¶

When the documentation says that the PHP parser ignores everything outside the ... ?> tags, it means literally EVERYTHING. Including things you normally wouldn't consider "valid", such as the following:2

When the documentation says that the PHP parser ignores everything outside the ... ?> tags, it means literally EVERYTHING. Including things you normally wouldn't consider "valid", such as the following:3

When the documentation says that the PHP parser ignores everything outside the ... ?> tags, it means literally EVERYTHING. Including things you normally wouldn't consider "valid", such as the following:4

if ($expression == true): ?>
  This will show if the expression is true.
else: ?>
  Otherwise this will show.
endif; ?>
0

11 năm trước

Ẩn danh ¶

When the documentation says that the PHP parser ignores everything outside the ... ?> tags, it means literally EVERYTHING. Including things you normally wouldn't consider "valid", such as the following:6

When the documentation says that the PHP parser ignores everything outside the ... ?> tags, it means literally EVERYTHING. Including things you normally wouldn't consider "valid", such as the following:7

When the documentation says that the PHP parser ignores everything outside the ... ?> tags, it means literally EVERYTHING. Including things you normally wouldn't consider "valid", such as the following:8

When the documentation says that the PHP parser ignores everything outside the ... ?> tags, it means literally EVERYTHING. Including things you normally wouldn't consider "valid", such as the following:9


if ($highlight): ?> class="highlight"endif;?>>This is a paragraph.


0

if ($expression == true): ?>
  This will show if the expression is true.
else: ?>
  Otherwise this will show.
endif; ?>
0

1 năm trước

Ẩn danh ¶


if ($highlight): ?> class="highlight"endif;?>>This is a paragraph.


2


if ($highlight): ?> class="highlight"endif;?>>This is a paragraph.


3


if ($highlight): ?> class="highlight"endif;?>>This is a paragraph.


4


if ($highlight): ?> class="highlight"endif;?>>This is a paragraph.


5

1 năm trước

Davidhcefx ¶


if ($highlight): ?> class="highlight"endif;?>>This is a paragraph.


6

2 năm trước

anisgazig.com


if ($highlight): ?> class="highlight"endif;?>>This is a paragraph.


7


if ($highlight): ?> class="highlight"endif;?>>This is a paragraph.


8

if ($expression == true): ?>
  This will show if the expression is true.
else: ?>
  Otherwise this will show.
endif; ?>
0