Longhorn PHP 2023 - Call for Papers

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

User Contributed Notes 2 notes

up
-3
irfan dot swen at gmail dot com
3 months ago
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>PHP Language</h1>
    <?php echo "1) PHP Special Syntax Code"; ?><br>

    <?= "2) PHP Special Syntax Code"; ?><br>

    <!-- Not Working-->  <? "3) PHP Special Syntax Code" ?> 
</body>
</html>
up
-59
anisgazig at gmail dot com
1 year ago
If you want your file to be interpreted as php then your file must start and end with <?php and ?> and everything outside of that is ignored by the php parser.

<?php
php code
..//parsed
php code..//parsed
?>
hellow..//normal test but ignred by php parser

Three types of tag are available in php
1.normal tag(<?php ?>)
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.
<?php
//php code;
//php code;
//php code;

but if you are embedding php with html then enclose php code with opening and closing tag.
<
html>
<
head>
</
head>
<
body>
<?
php
//php code;
//php code;
//php code;

?>
</body>
</html>

If you want to just print single text or something ,you should use shorthand version .<?= $var ?>

But if you want to process something, you should use normal tag.
<?php
       
//$var = 3;
        //$var2 = 2;
        //$var3 = $var+$var2;
        //if($var3){//result}

?>

If you embedded php with html and single line, do not need to use semicolon
<html>
<head>
<body>
<?= $var ?>
</body>
</head>
</html>
but if you have multiple line, then use semicolon.
<?php
//line 1;
//line 2;
//line 3;
?>
To Top