PHP etiketleri

PHP bir dosyayı çözümlerken, hangi bölümü yorumlayıp hangi bölümü yorumlamadan geçeceğine karar vermek için <?php ve ?> açılış ve kapanış etiketlerine bakar. Bu şekilde çözümleme PHP'nin her çeşit farklı belgeye gömülmesini sağlar, çünkü bir çift açılış ve kapanış etiketinin dışındaki her şey PHP çözümleyicisi tarafından gözardı edilir.

PHP daha açıklayıcı olan <?php echo etiketine bir kısaltma olarak <?= kısa echo etiketini içerir.

Örnek 1 - PHP Açılış ve Kapanış Etiketleri

1.  <?php echo 'XHTML veya XML belgelerde PHP kodu sunmak isterseniz,
                bu etiketleri kullanın'
?>

2.  Kısa echo etiketi kullanabilirsiniz: <?= 'print this string' ?>.
    <?php echo 'print this string' ?> koduna eşdeğerdir.

3.  <? echo 'bu kod kısa etiketler arasında olmakla birlikte sadece,'.
            'short_open_tag etkinse çalışır.'; ?>

PHP ayrıca kısa başlangıç etiketine de <? izin verir. Bu sadece, PHP --enable-short-tags yapılandırma seçeneği ile derlenerek veya php.ini yapılandırma dosyası yönergesi short_open_tag kullanılarak etkinleştirilebilir.

Bilginize:

Kısa etiketler iptal edilebileceğinden uyumluluk adına sadece normal etiketlerin (<?php ?> ve <?= ?>) kullanılması önerilir.

Bir dosya sadece PHP kodu içeriyorsa, dosyanın sonunda PHP kapanış etiketini koymamak tercih edilir. Yazılımcıdan herhangi bir çıktı gönderme isteği gelmezse PHP betiğin bu noktasında çıktı tamponlamasını başlatacağından kapama etiketinden sonra istenmeyen etkilere neden olabilecek boşluk veya yeni satırların yanlışlıkla eklenmesi böylece engellenmiş olur.

<?php
echo "Merhaba Dünya";

// ... daha kod

echo "İletişimin sonu";

// PHP kapama etiketi olmadan betik burada biter

add a note add a note

User Contributed Notes 2 notes

up
-4
admin at bharatt dot com dot np
2 years ago
You may want to know that removing semicolon is optional sometime but need to know the condition when it can be removed and when it can't be.
-------------------------------------------------------------------------
// Example 1: PHP script with closing tag at the end.
<?php

// php code

// you can remove semicolon
mysqli_close( $db )
?>

// Example 2: PHP script without closing tag at the end.
<?php

// php code

// you can't remove semicolon
mysqli_close( $db )

-----------------------------------------------------------------------
up
-64
anisgazig at gmail dot com
3 years ago
Everything inside a pair of opening and closing tag is interpreted by php parser. Php introduced three types of opening and closing tag.
1.Standard tags
<?php ?>
2.Short echo tag
<?=  ?>
here, <?=  is equivalent meaning of "<?php echo"
3.Short tag
<?   ?>

Standard tag and short echo tag are alwayes available.
But short tag can be disabled either via the short_open_tag php.ini configuration file directive, or are disabled by default if PHP is built with the --disable-short-tags configuration.

If a file contains only PHP code, it is preferable to omit the PHP closing tag at the end of the file.
This prevents accidental whitespace or new lines being added after the PHP closing tag
To Top