Tag PHP

Linda Hamilton
Lepaskan: 2024-10-17 20:17:03
asal
448 orang telah melayarinya

PHP Tags

In PHP there are several types of tags that can be used to embed PHP code within HTML or other documents. Let’s go over each of them, their differences, supported versions, and how to enable or disable them.

Standard PHP Tags

This is the syntax of standard PHP tags:

<?php
    echo "Bismillah!";
?>
Salin selepas log masuk
  • Supported Version: PHP 4 and later.
  • Always enabled by default, can not be disabled.
  • Recommended to use.

Short Open Tags ()

These are a shorthand of the standard PHP tags. This is the syntax:

<?
    echo "Alhamdulillah";
?>
Salin selepas log masuk
  • Supported Version: PHP 3 and later
  • Can be enabled or dsiabled by the short_open_tag directive in php.ini
  • To Enable: short_open_tag = On
  • To Disable: short_open_tag = Off
  • Not recommended to use because these can conflict with XML declarations.

Short Echo Tags ()

These are a shorthand for

<?= $message; ?>
Salin selepas log masuk
  • Supported version: PHP 5.4 and later
  • Enable/Disable: Always enabled in PHP 5.4 and later, regardless of the short_open_tag directive.
  • Use these for output but make sure that the server has them enabled.

ASP Style Tags (<% ... %>)

These tags are similar to ASP or JSP style tags:

<%
    echo "Assalamu Alaikum";
%>
Salin selepas log masuk
  • Supported Version: PHP 3 to PHP 7.0
  • Can be enabled or disabled by the asp_tags directive in php.ini (removed as of PHP 7.0)
  • Enable: asp_tags = On
  • Disable: asp_tags = Off
  • These are no longer supported in the modern versions of PHP.

Script Tags

This syntax allows you to embed PHP code in HTML like a script block.

<script language="php">
    echo "This is a script tag.";
</script>
Salin selepas log masuk
  • Supported version: PHP 3 and later.
  • These are always enabled but rarely used in modern applications. Not supported in XHTML and newer versions of HTML.

Atas ialah kandungan terperinci Tag PHP. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

sumber:dev.to
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel terbaru oleh pengarang
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!