Chapterبەش 5 · Lectureوانە 5.2

PHP Syntax: Tags, Statements and Commentsداڕستنی PHP: تاگ، ڕستە و لێدوان

The basic rules of writing PHP: .php files, PHP tags, statements and semicolons, case-sensitivity, language constructs and comments.

یاسا بنەڕەتییەکانی نووسینی PHP: ⁦.php⁩، ، و ، هەستیاری بە پیتی گەورە و بچووک، و .

23 min read23 خولەک خوێندنەوە · 19 stepsهەنگاو

What you will learnچی فێر دەبیت

  • Explain why PHP code must be in a .php file and how the server treats .html files.
  • Write PHP sections with the correct tags, and know which tag styles no longer work.
  • End statements correctly and read the error message for a missing semicolon.
  • Know which names in PHP are case-sensitive.
  • Write single-line and multi-line comments and use them well.
  • ڕوون بکەیتەوە بۆچی کۆدی PHP دەبێت لە ⁦.php⁩ـدا بێت و چۆن مامەڵە لەگەڵ ⁦.html⁩ دەکات.
  • کەرتی PHP بە دروست بنووسیت و بزانیت کام شێوەی ئیتر کار ناکەن.
  • بە دروستی کۆتایی پێبهێنیت و ون بخوێنیتەوە.
  • بزانیت کام ناوانە لە PHPـدا هەستیارن بە پیتی گەورە و بچووک.
  • تاکەدێڕ و فرەدێڕ بنووسیت و بە باشی بەکاریان بهێنیت.

Why syntax mattersبۆچی داڕستن گرنگە

Every language has rules. In Kurdish we put the verb at the end of the sentence; in English we put it after the subject. A programming language has rules too. These rules are called its .

هەموو زمانێک یاسای خۆی هەیە. لە کوردیدا کار لە کۆتایی ڕستەدا دادەنێین؛ لە ئینگلیزیدا لەدوای بکەر. یاسای هەیە. بەم یاسایانە دەگوترێت .

People can understand a sentence with small mistakes. The computer cannot. If one character of your PHP is in the wrong place, PHP stops and shows a , and the whole page may be empty. So in this lecture we learn the basic rules of writing PHP: where PHP code goes, how it starts and ends, how statements end, which names care about capital letters, and how to write comments.

مرۆڤ دەتوانێت لە ڕستەیەک تێبگات کە هەڵەی بچووکی تێدایە. ناتوانێت. ئەگەر تەنها یەک PHPـەکەت لە شوێنی خۆیدا نەبێت، PHP ڕادەوەستێت و پیشان دەدات و لەوانەیە هەموو لاپەڕەکە بەتاڵ بێت. بۆیە لەم وانەیەدا یاسا بنەڕەتییەکانی نووسینی PHP فێر دەبین: کۆدی PHP لە کوێ دادەنرێت، چۆن دەست پێدەکات و کۆتایی دێت، چۆن کۆتاییان دێت، کام ناوانە گرنگی بە پیتی گەورە دەدەن و چۆن دەنووسرێت.

A very strict post officeپۆستەخانەیەکی زۆر توند

Writing code is like writing an address on a letter at the post office. If you write the city in the wrong box, or forget the postcode, the letter does not arrive. PHP is a very strict post office: it reads every box, and it never guesses what you meant.

نووسینی کۆد وەک نووسینی ناونیشانە لەسەر نامەیەک لە پۆستەخانە. ئەگەر ناوی شارەکە لە خانەی هەڵەدا بنووسیت، یان کۆدی پۆستە لەبیر بکەیت، نامەکە ناگات. PHP پۆستەخانەیەکی زۆر توندە: هەموو خانەیەک دەخوێنێتەوە و هەرگیز مەزەندەی ئەوە ناکات کە مەبەستت چی بووە.

Where the analogy stops workingسنووری ئەم نموونەیە

A post-office worker may still deliver a letter with a small mistake. PHP does not: one missing semicolon stops the whole script.

کارمەندی پۆستەخانە لەوانەیە نامەیەک بە هەڵەیەکی بچووکەوە بگەیەنێت. PHP وا ناکات: تەنها یەک ون هەموو ڕادەگرێت.

Where PHP code goes: .php filesکۆدی PHP لە کوێ دادەنرێت: فایلی ⁦.php⁩

To use PHP in a website, you put PHP code inside your HTML pages. We say we embed PHP in HTML (). PHP code can be placed anywhere in the HTML: before it, after it, or in the middle of a line.

بۆ بەکارهێنانی PHP لە ، کۆدی PHP دەخەیتە ناو لاپەڕە HTMLـەکانتەوە. دەڵێین PHP لەناو HTMLـدا دادەکوتین (). کۆدی PHP دەتوانرێت لە هەر شوێنێکی HTMLـدا دابنرێت: پێشی، دوای، یان لە ناوەڕاستی دێڕێکدا.

Two rows. Top row: hello.php contains <p>, <?php echo "Hello"; ?> and </p>; the web server sees .php, gives the file to PHP, and the browser receives <p>Hello</p> and shows Hello. Bottom row: hello.html has the same code; the server sends it unchanged, the browser receives the PHP code, shows nothing, but View Source shows the code.دوو بەش. بەشی سەرەوە: فایلی hello.php کە <p> و <?php echo "Hello"; ?> و </p>ـی تێدایە؛ ڕاژەکار پاشگری فایلەکە، واتە .php، دەبینێت و فایلەکە دەداتە PHP، تۆڕگەڕ <p>Hello</p> وەردەگرێت و وشەی Hello پیشان دەدات. بەشی خوارەوە: فایلی hello.html هەمان کۆدی تێدایە؛ ڕاژەکار وەک خۆی دەینێرێت، تۆڕگەڕ کۆدی PHP وەردەگرێت و هیچ پیشان نادات، بەڵام View Source کۆدەکە پیشان دەدات.
The web server looks at the file extension. Only .php files are given to PHP. سەیری دەکات. تەنها ⁦.php⁩ دەدرێنە PHP.CêIT

PHP sections: one page, many blocks

کەرتی PHP: یەک لاپەڕە، چەند بلۆکێک

All PHP code is written between an opening tag <?php and a closing tag ?>. The Kurdish notes call one such block a PHP section («کەرتی PHP»). Between the tags you write PHP statements:

هەموو کۆدێکی PHP لە نێوان کردنەوە <?php و داخستن ?>دا دەنووسرێت. تێبینییە کوردییەکان بە بلۆکێکی وا دەڵێن کەرتی PHP. لە نێوان دوو PHP دەنووسیت:

The shape of a PHP sectionشێوەی کەرتێکی PHPPHP
<?php
    // PHP statements go here
    // ...
?>

A page may have two or more PHP sections, with HTML between them or not. This example from the Kurdish notes has two sections, each printing a word:

لاپەڕەیەک دەتوانێت دوو یان زیاتر کەرتی PHPـی هەبێت، HTMLـیان لە نێواندا بێت یان نا. ئەم نموونەیەی تێبینییە کوردییەکان دوو کەرتی هەیە و هەر یەکەیان وشەیەک دەنووسێت:

Two PHP sections in one fileدوو کەرتی PHP لە یەک فایلداtwo-sections.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
    echo "Kurd 1";
?>
<?php
    echo "Kurd 2";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1-3

The first section prints Kurd 1.

کەرتی یەکەم Kurd 1 دەنووسێت.

Lineدێڕی 4-6

The second section prints Kurd 2.

کەرتی دووەم Kurd 2 دەنووسێت.

Usually the sections sit inside a normal HTML page, like this:

زۆرجار کەرتەکان لەناو لاپەڕەیەکی HTMLـی ئاساییدان، بەم شێوەیە:

PHP in the middle of an HTML pagePHP لە ناوەڕاستی لاپەڕەیەکی HTMLـداfirst.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<!DOCTYPE html>
<html>
<body>
  <h1>My first PHP page</h1>
  <p><?php echo "This line was written by PHP."; ?></p>
  <p>This line is plain HTML.</p>
  <p><?php echo "PHP can appear many times in one page."; ?></p>
</body>
</html>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 5

A PHP section inside a <p> element.

کەرتێکی PHP لەناو <p>دا.

Lineدێڕی 6

Plain HTML: copied to the output as it is.

HTMLـی ئاسایی: وەک خۆی دەنووسرێتەوە بۆ .

Lineدێڕی 7

Another PHP section in the same page.

کەرتێکی تری PHP لە هەمان لاپەڕەدا.

Quick checkپشکنینی خێراA file is called news.html and contains <?php echo "Hi"; ?>. What happens? ناوی news.htmlـە و <?php echo "Hi"; ?>ـی تێدایە. چی ڕوودەدات؟

PHP tags: escaping from HTML to PHPتاگەکانی PHP: چوونە دەرەوە لە HTML بۆ PHP

The tags tell PHP where PHP code starts and ends. Leaving HTML and entering PHP is called escaping to PHP. The slides show four styles of tags. Only some of them still work:

بە PHP دەڵێن کۆدی PHP لە کوێ دەست پێدەکات و لە کوێ کۆتایی دێت. جێهێشتنی HTML و چوونە ناو PHP پێی دەگوترێت ⁦escaping to PHP⁩. سلایدەکان چوار شێوەی پیشان دەدەن. تەنها هەندێکیان هێشتا کار دەکەن:

The tag styles from the slides, and what they do todayشێوەکانی لە سلایدەکانەوە و ئەوەی ئەمڕۆ دەیکەن
StyleشێوەExampleنموونەIn PHP 8لە ⁦PHP 8⁩دا
Canonical PHP tags ستانداردی PHP<?php ... ?>Always works. Use this one.هەمیشە کار دەکات. ئەمە بەکار بهێنە.
Short echo tag کورتی echo<?= ... ?>Always works (since PHP 5.4). A short way to write <?php echo ... ?>.هەمیشە کار دەکات (لە ⁦PHP 5.4⁩ـەوە). شێوەیەکی کورتە بۆ نووسینی <?php echo ... ?>.
Short open tags (SGML style) کورتی کردنەوە (شێوەی SGML)<? ... ?>Works only if the setting short_open_tag is on. Many servers switch it off, so avoid it.تەنها کار دەکات ئەگەر short_open_tag لە کرابێتەوە. زۆر دایدەخەن، بۆیە خۆتی لێ بپارێزە.
ASP-style tags شێوەی ASP<% ... %>Removed in PHP 7.0. No setting can turn it on. The code is sent to the browser as text.لە ⁦PHP 7.0⁩دا لابرا. هیچ ناتوانێت بیکاتەوە. کۆدەکە وەک دەق دەنێردرێت بۆ .
HTML script tag script ـی HTML<script language="php"> ... </script>Removed in PHP 7.0. The code is sent to the browser as text.لە ⁦PHP 7.0⁩دا لابرا. کۆدەکە وەک دەق دەنێردرێت بۆ .

Here is a test page with all four working and non-working styles. Look at what PHP sends:

ئەمە لاپەڕەیەکی تاقیکردنەوەیە بە شێوە کاراکان و ناکاراکانەوە. سەیر بکە PHP چی دەنێرێت:

Which tags still work?کام تاگ هێشتا کار دەکەن؟tags.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<p>1: <?php echo "canonical tag"; ?></p>
<p>2: <?= "short echo tag" ?></p>
<p>3: <% echo "ASP-style tag"; %></p>
<p>4: <script language="php">echo "script tag";</script></p>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

The canonical tag: the code runs.

ستاندارد: کۆدەکە جێبەجێ دەکرێت.

Lineدێڕی 2

The short echo tag prints the value directly.

کورتی echo ڕاستەوخۆ دەنووسێت.

Lineدێڕی 3-4

Removed styles: PHP copies them to the output as if they were HTML. The PHP code inside them is sent to the visitor!

شێوە لابراوەکان: PHP وەک HTML دەیاننووسێتەوە بۆ . کۆدی PHPـی ناویان دەنێردرێت بۆ سەردانیکەر!

Definitionپێناسە

PHP's main configuration file. It sets options such as file_uploads, upload_max_filesize, post_max_size and max_execution_time; restart after changing it.

بریتییە لە فایلی سەرەکیی PHP. هەڵبژاردەی وەک file_uploads، upload_max_filesize، post_max_size و max_execution_time تێیدا دیاری دەکرێن؛ دوای گۆڕینی، دابخە و دووبارە هەڵیبکەرەوە.

The slide calls it “the settings file that controls how PHP behaves on that server”. You can see its settings with phpinfo() (XAMPP lecture).

سلایدەکە پێی دەڵێت «ئەو کە ڕەفتاری PHP لەسەر ئەو کۆنترۆڵ دەکات». دەتوانیت بە phpinfo() ببینیت (وانەی XAMPP).

Quick checkپشکنینی خێراWhich PHP tag style should you always use?کام شێوەی دەبێت هەمیشە بەکاری بهێنیت؟

Basic PHP Syntax - PHP 8 TutorialProgram With Gio · Englishئینگلیزی · 237K viewsبینین · 4.8K likesلایک · Partبەشی 0:41–1:58 (ofلە 12:32)

Explains the PHP opening and closing tags (and why to leave out ?> in pure PHP files), and the kinds of PHP comments.

کردنەوە و داخستنی ڕوون دەکاتەوە، بۆچی لەو تەنها تێدایە ?> نانووسین و جۆرەکانی لە .

Watch 0:41 to 1:58: PHP tags and the closing tag

لە ⁦0:41⁩ تا ⁦1:58⁩ سەیر بکە: و داخستن.

PHP tags: escaping from HTML to PHPتاگەکانی PHP: چوونە دەرەوە لە HTML بۆ PHP

The closing tag ?>تاگی داخستنی ?>

  • The closing tag ?> also ends the last statement, so a semicolon just before it is optional (see Statements). Still, write the semicolon: it is good practice.
  • PHP removes one line break directly after ?>, as you saw in the “Kurd 1Kurd 2” example.
  • If a file contains only PHP code (no HTML), it is best to leave out the final ?>. Then no space or empty line after it can be sent by mistake. This matters later, when you send headers or redirects (see Redirects).
  • داخستنی ?> دوایین کۆتایی پێدەهێنێت، بۆیە ڕاستەوخۆ پێش ئەو ئارەزوومەندانەیە (بڕوانە ڕستەکان). هێشتا بنووسە: ئەمە ڕەفتارێکی باشە.
  • PHP یەک دێڕبڕین ڕاستەوخۆ لەدوای ?> لادەبات، وەک لە نموونەی «⁦Kurd 1Kurd 2⁩»دا بینیت.
  • ئەگەر تەنها کۆدی PHPـی تێدا بێت (بێ HTML)، باشترە ?>ـی کۆتایی دانەنێیت. ئەوکاتە هیچ یان دێڕێکی بەتاڵ لەدوای ئەوەوە بە هەڵە نانێردرێت. ئەمە دواتر گرنگ دەبێت، کاتێک یان دەنێریت (بڕوانە ئاڕاستەکردنەوە).

Statements and the semicolonڕستە و خاڵبۆر

A PHP is one instruction that tells the computer to do something. A PHP is made of PHP statements; it can even be a single statement.

ی PHP یەک ڕێنماییە کە بە دەڵێت کارێک بکات. ی PHP لە کۆمەڵێک PHP پێکدێت؛ تەنانەت دەکرێت تەنها یەک بێت.

One of the most common statements is the echo statement. Its job is to put on the screen: it outputs whatever is between the two quotation marks. So the statement below puts the word Kurdistan on the screen:

یەکێک لە باوترین echoـە. کارەکەی ئەوەیە کە بخاتە سەر : هەرچی لە نێوان دوو بێت دەینووسێت. بۆیە ئەم خوارەوە وشەی Kurdistan دەخاتە سەر :

A simple statementڕستەیەکی سادەPHP
echo "Kurdistan";

Simple PHP statements end with a ;. The semicolon is also called the : it marks the end of one instruction. PHP reads each statement until it meets a semicolon. Two statements in a row:

سادەکانی PHP بە ; کۆتاییان دێت. بە دەگوترێت ـیش: کۆتایی ڕێنماییەک دیاری دەکات. PHP هەر دەخوێنێتەوە تا دەگاتە . دوو لەدوای یەک:

two-statements.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "Kurdistan";
echo "Erbil";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2-3

Each echo statement ends with ;.

هەر echo بە ; کۆتایی دێت.

Statements and the semicolonڕستە و خاڵبۆر

What happens if you forget the semicolon?ئەگەر خاڵبۆر لەبیر بکەیت چی ڕوودەدات؟

Remove the semicolon after the first statement. PHP no longer knows where the first instruction ends, so it stops with an error message:

دوای یەکەم لاببە. PHP ئیتر نازانێت ڕێنمایی یەکەم لە کوێ کۆتایی دێت، بۆیە بە ڕادەوەستێت:

A missing semicolonخاڵبۆری ونsemicolon.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "Kurdistan"
echo "Erbil";
?>

Read the message carefully: unexpected token "echo", expecting "," or ";" means “I found the word echo, but I expected a comma or a semicolon”. Notice the line number: PHP reports line 3, where it noticed the problem, but the missing semicolon is at the end of line 2. Always look at the line before, too. If the statement without a semicolon is the last one in the file, the message is different:

پەیامەکە بە وردی بخوێنەوە: unexpected token "echo", expecting "," or ";" واتە «وشەی echoم بینی، بەڵام چاوەڕێی کۆما یان بووم». سەرنجی ژمارەی دێڕەکە بدە: PHP دەڵێت دێڕی 3، کە لەوێ کێشەکەی بینی، بەڵام ونەکە لە کۆتایی دێڕی 2دایە. هەمیشە سەیری دێڕی پێشەوەش بکە. ئەگەر ئەو نییە دوایین بێت لە ، پەیامەکە جیاوازە:

semicolon2.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "Kurdistan"
Quick checkپشکنینی خێراPHP says: Parse error: syntax error, unexpected token "echo", expecting "," or ";" ... on line 7. Where should you look for the missing semicolon?PHP دەڵێت: Parse error: syntax error, unexpected token "echo", expecting "," or ";" ... on line 7. لە کوێ بەدوای ونەکەدا بگەڕێیت؟

Statements and the semicolonڕستە و خاڵبۆر

A semicolon before ?> is optionalخاڵبۆر پێش ?> ئارەزوومەندانەیە

The closing tag ?> ends a statement by itself, so this line works without a semicolon:

داخستنی ?> خۆی کۆتایی پێدەهێنێت، بۆیە ئەم دێڕە بەبێ کار دەکات:

PHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php echo "Kurdistan" ?>

Statements and the semicolonڕستە و خاڵبۆر

Spaces and new lines do not matterبۆشایی و دێڕی نوێ گرنگ نین

Between the parts of a statement you may put any number of spaces, tabs and new lines. PHP looks for the semicolon, not for the end of the line. So one statement may cover several lines, and this works (but it is hard to read):

لە نێوان بەشەکانی دەتوانیت هەر ژمارەیەک ، تاب و دێڕی نوێ دابنێیت. PHP بەدوای دەگەڕێت، نەک بەدوای کۆتایی دێڕدا. بۆیە یەک دەتوانێت چەند دێڕێک بگرێتەوە و ئەمە کار دەکات (بەڵام خوێندنەوەی قورسە):

spaces.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo     "Erbil"   ;
echo
    " and "
    ;
echo "Duhok";
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3-5

One echo statement written over three lines. It ends at the ; on line 5.

یەک echo کە لە سێ دێڕدا نووسراوە. لە ;ـی دێڕی 5دا کۆتایی دێت.

Statements and the semicolonڕستە و خاڵبۆر

Simple and complex statementsڕستەی سادە و ڕستەی ئاڵۆز

The Kurdish notes name two kinds of statements:

تێبینییە کوردییەکان ناوی دوو جۆر دەبەن:

  • A simple statement does one thing, for example showing a word or a sentence with the keyword echo. It ends with a semicolon.
  • A complex statement contains other statements inside a { ... }, for example a statement with a (if) or a loop. There is no semicolon after the closing brace }, but the simple statements inside the braces still need their semicolons.
  • یەک کار دەکات، بۆ نموونە پیشاندانی وشەیەک یان دەستەواژەیەک بە echo. بە کۆتایی دێت.
  • تری تێدایە لەناو { ... }، بۆ نموونە کە تێدایە (if) یان . لەدوای کەوانەی داخستنی } نییە، بەڵام سادەکانی ناو کەوانەکان هێشتا پێویستیان بە هەیە.
A complex statementڕستەیەکی ئاڵۆزpray.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$time = "night";
if ($time == "night") {
    echo "Pray";
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

A simple statement: it stores the text night in the variable $time. You will learn variables in Variables.

سادە: دەقی night لە $timeدا هەڵدەگرێت. لە وانەی گۆڕاوەکان فێر دەبیت.

Lineدێڕی 3

if starts a complex statement: the code in the braces runs only when the condition is true. See Conditionals.

if ئاڵۆز دەست پێدەکات: کۆدی ناو کەوانەکان تەنها کاتێک جێبەجێ دەبێت کە ڕاست بێت. بڕوانە مەرجەکان.

Lineدێڕی 4

A simple statement inside the block: it still needs ;.

سادە لەناو بلۆکەکەدا: هێشتا پێویستی بە ; هەیە.

Lineدێڕی 5

No semicolon after }.

لەدوای } نییە.

Quick checkپشکنینی خێراWhere is a semicolon not needed? لە کوێ پێویست نییە؟

Statements and the semicolonڕستە و خاڵبۆر

Language constructsپێکهاتەکانی زمان

Definitionپێناسە

A built-in part of the PHP language that looks like a function but is not one, such as echo, print, isset, empty, include and require. Some, like echo, can be used without parentheses.

بەشێکی ناوەکیی زمانی PHPـیە کە لە دەچێت بەڵام لە ڕاستیدا نییە، وەک echo و print و isset و empty و include و require. هەندێکیان، وەک echo، بەبێ کەوانە بەکار دێن.

In simple words, a is a word that is built into PHP and has a fixed meaning. PHP recognises it directly, so you do not call it like a normal , and many constructs do not need parentheses. Constructs either do basic jobs, such as printing text, or form the structure of the code.

بە زمانێکی سادە، وشەیەکە کە لەناو خودی PHPـدا دروست کراوە و واتایەکی جێگیری هەیە. PHP ڕاستەوخۆ دەیناسێتەوە، بۆیە وەک ئاسایی بانگی ناکەیت و زۆربەیان پێویستیان بە کەوانە نییە. ئەمانە یان کاری بنەڕەتی دەکەن، وەک نووسینی دەق، یان پێکهاتەی کۆدەکە دروست دەکەن.

Language constructs and keywords و
KindجۆرExamplesنموونە
Constructs that look like functionsئەوانەی لە دەچنecho, print, isset, empty, unset, include, require, list, array()
Keywords that build the structure of code (control structures and declarations) پێکهاتەی کۆد ( و ناساندن)if, else, while, for, switch, try, catch, function, class

Because echo is a construct and not a function, you can write it with or without parentheses, and you cannot use it like a function in other ways. This example shows the difference:

لەبەر ئەوەی echo نەک ، دەتوانیت بە کەوانە یان بەبێ کەوانە بینووسیت و ناتوانیت بە شێوەکانی تر وەک بەکاری بهێنیت. ئەم نموونەیە جیاوازییەکە پیشان دەدات:

construct.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "Hello", " ", "World";
echo ("!");
$f = "strtoupper";
echo $f(" erbil");
$g = "echo";
$g(" duhok");
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

echo with three items and no parentheses.

echo بە سێ بڕگە و بەبێ کەوانە.

Lineدێڕی 3

Parentheses are allowed around one value, but they are not a function call.

کەوانە لە دەوری یەک ڕێگەپێدراوە، بەڵام نییە.

Lineدێڕی 4-5

strtoupper is a real function, so PHP can call it through a variable that holds its name.

strtoupper ڕاستەقینەیە، بۆیە PHP دەتوانێت لە ڕێگەی کە ناوەکەی تێدایە بانگی بکات.

Lineدێڕی 6-7

echo is not a function, so the same trick fails with an error.

echo نییە، بۆیە هەمان فێڵ بە سەرناکەوێت.

exit() stops the script⁦exit()⁩ دەسنووسەکە ڕادەگرێتexit.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "Before exit. ";
exit("Goodbye.");
echo "This line never runs.";
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

exit("Goodbye.") prints its message and stops the script. die() does the same. You will meet them again in Including files.

exit("Goodbye.") پەیامەکەی دەنووسێت و ڕادەگرێت. die()یش هەمان کار دەکات. دیسان لە وانەی هاوردەکردنی فایل دەیانبینیتەوە.

Lineدێڕی 4

This line never runs.

ئەم دێڕە هەرگیز جێبەجێ نابێت.

Quick checkپشکنینی خێراWhich of these is a real function in PHP 8.5, and not a language construct?کامیان لە ⁦PHP 8.5⁩دا ڕاستەقینەیە و نییە؟

PHP For Beginners | 3+ Hour Crash CourseTraversy Media · Englishئینگلیزی · 926K viewsبینین · 18K likesلایک · Partبەشی 18:20–26:35 (ofلە 3:15:36)

Shows the language constructs echo and print next to the functions print_r and var_dump, so you see the difference between a construct and a function.

و کە ، لە تەنیشت print_r و var_dump نیشان دەدات، تا جیاوازیی و ببینیت.

Watch 18:20 to 26:35: Output Constructs & Functions chapter

لە ⁦18:20⁩ تا ⁦26:35⁩ سەیر بکە: بەشی Output Constructs & Functions.

Capital letters: what is case-sensitive?پیتی گەورە و بچووک: چی هەستیارە؟

A name is when Name, name and NAME count as three different names. The slides say that PHP's language constructs are “mostly case-insensitive”. That is true, but there are important exceptions:

ناوێک ـە کاتێک Name و name و NAME وەک سێ ناوی جیاواز دادەنرێن. سلایدەکان دەڵێن PHP «زۆربەیان هەستیار نین». ئەمە ڕاستە، بەڵام هەڵاوێردەی گرنگ هەن:

Case-sensitivity rules in PHP 8یاساکانی هەستیاری بە پیتی گەورە و بچووک لە ⁦PHP 8⁩دا
WhatچیCase-sensitive?هەستیارە؟Exampleنموونە
Keywords and language constructs و Noنەخێرecho = Echo = ECHO; if = IF
Function namesناوی Noنەخێرstrtoupper() = STRTOUPPER(); phpinfo() = phpINFO()
Variable namesناوی Yesبەڵێ$city ≠ $CITY
Constant namesناوی YesبەڵێCITY ≠ city

Keywords: any case works

وشە کلیلەییەکان: هەر شێوەیەک کار دەکات

This example from the slides uses echo, Echo and ECHO. All three work:

ئەم نموونەیەی سلایدەکان echo و Echo و ECHO بەکار دەهێنێت. هەر سێکیان کار دەکەن:

explore.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "<p>Explore <strong>Africa</strong>, <br />";
Echo "<strong>South America</strong>, <br />";
ECHO " and <strong>Australia</strong>!</p>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2-4

Three spellings of the same construct echo.

سێ شێوەی نووسینی هەمان echo.

And the example from the summary prints the same word three times:

نموونەکەی کورتەکەش هەمان وشە سێ جار دەنووسێت:

hello3.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
Echo "Hello";
EChO "Hello";
echo "Hello";

Function names are not case-sensitive either, and neither are keywords such as if:

ناوی هەستیار نین، هەروەها وەک if:

functions.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo strtoupper("erbil "), STRTOUPPER("duhok "), StrToUpper("zakho");
IF (true) {
    ECHO "<br>Keywords work in any case.";
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

strtoupper() changes text to capital letters. Three spellings of its name all work.

strtoupper() دەق دەگۆڕێت بۆ پیتی گەورە. هەر سێ شێوەی نووسینی ناوەکەی کار دەکەن.

Lineدێڕی 3-5

IF and ECHO in capitals also work.

IF و ECHO بە پیتی گەورەش کار دەکەن.

Variables and constants: the case matters

گۆڕاو و نەگۆڕ: شێوەی پیت گرنگە

The slide does not mention this exception, but it causes many mistakes: variable names are case-sensitive. $city and $CITY are two different variables:

سلایدەکە باسی ئەم هەڵاوێردەیە ناکات، بەڵام زۆر دروست دەکات: ناوی هەستیارن. $city و $CITY دوو جیاوازن:

vars.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$city = "Erbil";
echo $city;
echo $CITY;
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

Create the variable $city.

$city دروست بکە.

Lineدێڕی 4

$CITY is a different variable that was never created, so PHP shows a warning and prints nothing for it.

$CITY جیاوازە کە هەرگیز دروست نەکراوە، بۆیە PHP پیشان دەدات و هیچ شتێک بۆی نانووسێت.

Constant names are case-sensitive too. In PHP 8 an unknown constant is a fatal error:

ناوی هەستیارن. لە ⁦PHP 8⁩دا نەناسراو :

constants.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
define("CITY", "Sulaimani");
echo CITY;
echo city;
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

define() creates the constant CITY. Constants are explained in Constants and scope.

define() CITY دروست دەکات. لە وانەی نەگۆڕ و مەودا ڕوون کراونەتەوە.

Lineدێڕی 4

city in small letters is another name, which does not exist.

city بە پیتی بچووک ناوێکی ترە کە بوونی نییە.

Quick checkپشکنینی خێراWhich pair of names means the same thing to PHP?کام دوو ناو بۆ PHP هەمان شتن؟

Commentsلێدوان

A is text in your code that PHP ignores. It is not run and it is not shown on the screen. Comments are only for the human reader: to help others understand what you did, and to remind yourself when you come back to a large program and have forgotten the details. Comments are also used when looking for errors: you can turn a line into a comment to switch it off for a moment. A comment can be as short or as long as you like.

دەقێکە لە کۆدەکەتدا کە PHP فەرامۆشی دەکات. جێبەجێ ناکرێت و لەسەر پیشان نادرێت. تەنها بۆ خوێنەری مرۆڤن: بۆ ئەوەی یارمەتی کەسانی تر بدەن لەوەی کردووتە تێبگەن و بۆ ئەوەی کاتێک دەگەڕێیتەوە سەر گەورە و وردەکارییەکانت لەبیر چووە، بیرت بخەنەوە. لە کاتی بەدواداگەڕانی بەکار دێن: دەتوانیت دێڕێک بکەیتە بۆ ئەوەی بۆ ماوەیەک بیکوژێنیتەوە. دەتوانێت هێندەی بتەوێت کورت یان درێژ بێت.

PHP has two kinds of comments:

PHP دوو جۆر هەیە:

The two kinds of PHP commentsدوو جۆری لە PHPـدا
KindجۆرHow to write itچۆن دەنووسرێتUsed forبۆ چی بەکار دێت
Single-line comment تاکەدێڕ// ... or # ...Short explanations or notes. It ends at the end of the line.ڕوونکردنەوە یان تێبینیی کورت. لە کۆتایی دێڕەکەدا کۆتایی دێت.
Multi-line comment فرەدێڕ/* ... */Longer explanations, for example how an algorithm works. It can cover any number of lines.ڕوونکردنەوەی درێژتر، بۆ نموونە چۆنیەتی کارکردنی . دەتوانێت هەر ژمارەیەک دێڕ بگرێتەوە.
All comment stylesهەموو شێوەکانی لێدوانcomments.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
// This is a single-line comment
# This is also a single-line comment
/* This is a multi-line comment.
   It can be as long as you like. */
echo "Kurd"; // A comment after a statement
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

A single-line comment starting with two slashes //.

تاکەدێڕ کە بە دوو لارەهێڵ // دەست پێدەکات.

Lineدێڕی 3

A single-line comment starting with the hash sign # (the Kurdish notes call it «هێمای پەنجەرە»).

تاکەدێڕ کە بە هێمای # دەست پێدەکات (تێبینییە کوردییەکان پێی دەڵێن «هێمای پەنجەرە»).

Lineدێڕی 4-5

A multi-line comment: everything from /* to */ is ignored.

فرەدێڕ: هەموو شتێک لە /*ـەوە تا */ فەرامۆش دەکرێت.

Lineدێڕی 6

A comment can also come after a statement, after its semicolon.

دەتوانێت لەدوای بێت، لەدوای .

These are the comment examples exactly as the slides and the Kurdish notes give them:

ئەمانە نموونەکانی هەروەک سلاید و تێبینییە کوردییەکان داویانن:

course-comments.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
// single line comments are like this
# or like this

/* our double line comment here
and we can keep typing
and typing
*/

# This is a comment
// This is a comment too.

/* This is a comment
   with multiline
   Author: Multiline Comments Demo
   Subject: PHP */

/*
	This is the first line of the comment,
	this is the second line of the comment.
*/

# This is a single line comment
// This is a single line comment

echo "Kurd"; //This is a comment
Basic PHP Syntax - PHP 8 TutorialProgram With Gio · Englishئینگلیزی · 237K viewsبینین · 4.8K likesلایک · Partبەشی 10:45–12:32 (ofلە 12:32)

Explains the PHP opening and closing tags (and why to leave out ?> in pure PHP files), and the kinds of PHP comments.

کردنەوە و داخستنی ڕوون دەکاتەوە، بۆچی لەو تەنها تێدایە ?> نانووسین و جۆرەکانی لە .

Watch 10:45 to the end: PHP comments

لە ⁦10:45⁩ تا کۆتایی سەیر بکە: .

Commentsلێدوان

Three details about commentsسێ وردەکاری دەربارەی لێدوان

1. A single-line comment also ends at ?>

١. لێدوانی تاکەدێڕ لە ?>یشدا کۆتایی دێت

A single-line comment ends at the end of the line or at ?>, whichever comes first. Text after ?> is HTML again:

تاکەدێڕ لە کۆتایی دێڕەکەدا یان لە ?>دا کۆتایی دێت، کامیان زووتر بێت. دەقی دوای ?> دیسان HTMLـە:

close.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<p><?php echo "A"; // this comment ends here ?> B</p>

2. Multi-line comments cannot be nested

٢. لێدوانی فرەدێڕ ناکرێت لەناو یەکتردا بن

A multi-line comment ends at the first */. So you cannot put one /* */ comment inside another: the rest becomes code, and PHP stops with an error.

فرەدێڕ لە یەکەم */دا کۆتایی دێت. بۆیە ناتوانیت /* */ بخەیتە ناو یەکێکی ترەوە: ئەوەی دەمێنێتەوە دەبێت بە کۆد و PHP بە ڕادەوەستێت.

nested.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
/* outer comment
   /* inner comment */
   this line is no longer inside a comment
*/
echo "done";

3. Do not start a comment with #[

٣. لێدوان بە #[ دەست پێمەکە

Since PHP 8, #[ starts an attribute (a special PHP 8 feature), not a comment. So a line that begins with #[ is read as code:

لە ⁦PHP 8⁩ـەوە، #[ attributeێک دەست پێدەکات (تایبەتمەندییەکی تایبەتی ⁦PHP 8⁩)، نەک . بۆیە دێڕێک کە بە #[ دەست پێبکات وەک کۆد دەخوێنرێتەوە:

attribute.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
#[This looks like a comment]
echo "Hello";
Quick checkپشکنینی خێراWhich line is not a comment in PHP 8?کام دێڕ لە ⁦PHP 8⁩دا نییە؟

Commentsلێدوان

PHP comments and HTML commentsلێدوانی PHP و لێدوانی HTML

HTML has its own comments, <!-- ... -->. They look similar, but there is a big difference: an HTML comment is sent to the browser (anyone can read it with View Source), while a PHP comment is removed on the server and never leaves it.

HTML تایبەتی خۆی هەیە، <!-- ... -->. لە یەک دەچن، بەڵام جیاوازییەکی گەورە هەیە: HTML دەنێردرێت بۆ (هەرکەسێک دەتوانێت بە ⁦View Source⁩ بیخوێنێتەوە)، بەڵام PHP لەسەر لادەبرێت و هەرگیز لەوێ دەرناچێت.

two-comments.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<!-- HTML comment: the browser receives this -->
<?php // PHP comment: the browser never receives this ?>
<p>Hello</p>

Commentsلێدوان

Writing good commentsنووسینی لێدوانی باش

The code already says what it does. A good comment says why you did it that way. The slides call this: “Comment the why, not the what.”

کۆدەکە خۆی دەڵێت چی دەکات. باش دەڵێت بۆچی بەو شێوەیە کردووتە. سلایدەکان پێی دەڵێن: «هۆکار بنووسە، نەک کارەکە.»

A weak comment and a useful oneلێدوانێکی لاواز و لێدوانێکی بەسوودPHP
<?php
// Bad: says only what the code already says
$total = $price * 1.15; // multiply by 1.15

// Good: says why
$total = $price * 1.15; // add 15% service charge

You can also use comments to find errors. Put // in front of a line to switch it off for a moment, then run the page again:

دەتوانیت بۆ دۆزینەوەی بەکار بهێنیت. // بخەرە پێش دێڕێک بۆ ئەوەی بۆ ماوەیەک بیکوژێنیتەوە، پاشان لاپەڕەکە دووبارە کار پێبکەرەوە:

find-error.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "Line 1 ";
// echo "Line 2 ";
echo "Line 3";
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

This line is “commented out”: PHP ignores it.

ئەم دێڕە کراوە بە : PHP فەرامۆشی دەکات.

Common mistakesهەڵە باوەکان

The course materials contain several of these mistakes themselves. Learn to recognise them.

خودی کەرەستەکانی کۆرسەکە هەندێک لەم هەڵانەیان تێدایە. فێر ببە بیانناسیتەوە.

Common syntax mistakes باوەکانی
MistakeWhat happensچی ڕوودەداتFixچارەسەر
Curly quotes “ ” from Word, PowerPoint or a phone چەماوە “ ” لە Word، PowerPoint یان مۆبایلەوەParse error or “Undefined constant” error یان «⁦Undefined constant⁩»Type code in a code editor; use straight quotes " and 'کۆد لە دەستکاریکەرێکی کۆددا بنووسە؛ ڕاست " و ' بەکار بهێنە
Missing semicolon ونParse error, often reported on the next line، زۆرجار لە دێڕی دواتردا ڕادەگەیەنرێتEnd every simple statement with ;هەموو سادە بە ; کۆتایی پێبهێنە
File saved as .html وەک .html پاشەکەوت کراوەThe PHP code is not run and is sent to the browserکۆدی PHP جێبەجێ ناکرێت و دەنێردرێت بۆ Save the file as .php and open it through http://localhost/... وەک .php پاشەکەوت بکە و لە ڕێگەی http://localhost/...ـەوە بیکەرەوە
Old tags <% %> or <script language="php"> کۆنی <% %> یان <script language="php">Not run; the code is sent to the visitorجێبەجێ ناکرێت؛ کۆدەکە دەنێردرێت بۆ سەردانیکەرUse <?php ... ?><?php ... ?> بەکار بهێنە
$Name in one place, $name in another$Name لە شوێنێک، $name لە شوێنێکی ترWarning: Undefined variable: ⁦Undefined variable⁩Spell each variable the same way every timeهەموو جارێک هەر بە هەمان شێوە بنووسە
A /* comment that is never closed, or one comment inside another /* کە هەرگیز دانەخراوە، یان لەناو یەکێکی ترداCode is hidden by mistake, or a parse errorکۆد بە هەڵە دەشاردرێتەوە، یان Close every /* with */; do not nest themهەموو /*ێک بە */ دابخە؛ مەیانخە ناو یەکترەوە

Curly quotes deserve a closer look. Exercise 2 of Lab 1 was printed with curly quotes. Copied as it is, it fails:

چەماوە شایەنی سەرنجێکی زیاترە. ڕاهێنانی 2ی تاقیگەی 1 بە نیشانەی چەماوە چاپ کرابوو. ئەگەر وەک خۆی کۆپی بکرێت، سەرناکەوێت:

Lab 1, Exercise 2 as printed (does not work)ڕاهێنانی 2ی تاقیگەی 1 وەک چاپ کراوە (کار ناکات)lab1-ex2-as-printed.phpTEXT
<?php
// Displaying H
echo “Hello World”;
?>

With a single word in curly quotes, as in the Kurdish notes (echo “Kurdistan”;), the error is different, because PHP reads “Kurdistan” as the name of a constant:

کاتێک تەنها یەک وشە لەنێو نیشانەی چەماوەدا بێت، وەک لە تێبینییە کوردییەکاندا (echo “Kurdistan”;)، جیاوازە، چونکە PHP “Kurdistan” وەک ناوی دەخوێنێتەوە:

Output of echo “Kurdistan”;دەرخستەی echo “Kurdistan”;
Fatal error: Uncaught Error: Undefined constant "“Kurdistan”" in kurdistan.php:2
Stack trace:
#0 {main}
  thrown in kurdistan.php on line 2

PHP prints the full path of the file in its messages; here we show only the file name.

PHP لە پەیامەکانیدا تەواوی دەنووسێت؛ لێرەدا تەنها ناوی داناوە.

Practiceڕاهێنان

ExerciseڕاهێنانHello World with echo⁦Hello World⁩ بە echo

Lab 1, Exercise 2. Print a simple “Hello World” using PHP code. We use echo for printing. Create a new PHP file in your project (in NetBeans, VS Code or the htdocs folder of XAMPP), type the code, and run it in the browser.

تاقیگەی 1، ڕاهێنانی 2. بە کۆدی PHP «⁦Hello World⁩»ێکی سادە بنووسە. بۆ نووسین echo بەکار دەهێنین. نوێی PHP لە پرۆژەکەتدا دروست بکە (لە NetBeans، ⁦VS Code⁩ یان htdocsی XAMPP)، کۆدەکە بنووسە و لە کاری پێبکە.

Hintئاماژە

Use straight quotes, and end the statement with a semicolon.

ڕاست بەکار بهێنە و بە کۆتایی پێبهێنە.

Show answerوەڵامەکە پیشان بدە
hello.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
// Displaying Hello World
echo "Hello World";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

The comment in the lab sheet was cut off (“// Displaying H”). It means “Displaying Hello World”.

پەڕەی تاقیگەکە بڕابوو («// ⁦Displaying H⁩»). مەبەستی «⁦Displaying Hello World⁩»ـە.

ExerciseڕاهێنانBreak it on purposeبە ئەنقەست تێکی بدە

Break it on purpose. Take your working Hello World file. Remove the semicolon and run it. Read the error message: which line does it name? Put the semicolon back, then change one straight quote into a curly quote “ and run it again. What is the message now? This is how you learn to read errors.

بە ئەنقەست تێکی بدە. ⁦Hello World⁩ـە کارکەرەکەت وەربگرە. لاببە و کاری پێبکە. بخوێنەوە: ناوی کام دێڕ دەبات؟ بگەڕێنەوە، پاشان یەکێک لە نیشانە ڕاستەکان بگۆڕە بۆ نیشانەیەکی چەماوە “ و دووبارە کاری پێبکە. ئێستا پەیامەکە چییە؟ بەم شێوەیە فێر دەبیت بخوێنیتەوە.

Show answerوەڵامەکە پیشان بدە

Without the semicolon (and with ?> on the next line), the file still works, because ?> ends the statement. If you also remove ?>, you get Parse error: syntax error, unexpected end of file, expecting "," or ";". With a curly quote the message depends on which quote you changed. If you change the opening quote (echo “Hello World";), PHP says Parse error: syntax error, unexpected identifier "World", expecting "," or ";". If you change the closing quote (echo "Hello World”;), the string never ends, so PHP says Parse error: syntax error, unexpected end of file, expecting variable or "${" or "{$". The line number points at the line where PHP got confused; the real mistake may be on that line or the line before.

بەبێ (و بە ?> لە دێڕی دواتردا)، هێشتا کار دەکات، چونکە ?> کۆتایی پێدەهێنێت. ئەگەر ?>یش لاببەیت، Parse error: syntax error, unexpected end of file, expecting "," or ";" وەردەگریت. بە نیشانەیەکی چەماوە، پەیامەکە بەستراوەتەوە بەوەی کام نیشانەت گۆڕیوە. ئەگەر نیشانەی سەرەتا بگۆڕیت (echo “Hello World";)، PHP دەڵێت Parse error: syntax error, unexpected identifier "World", expecting "," or ";". ئەگەر نیشانەی کۆتایی بگۆڕیت (echo "Hello World”;)، هەرگیز کۆتایی نایەت، بۆیە PHP دەڵێت Parse error: syntax error, unexpected end of file, expecting variable or "${" or "{$". ژمارەی دێڕەکە ئەو دێڕە پیشان دەدات کە PHP تێیدا تێکچوو؛ ڕاستەقینەکە لەوانەیە لەو دێڕەدا بێت یان لە دێڕی پێشتر.

ExerciseڕاهێنانFind the mistakesهەڵەکان بدۆزەرەوە

Find and fix five mistakes in this script. Then write what it prints.

پێنج لەم بدۆزەرەوە و چاکیان بکە. پاشان بنووسە چی دەنووسێت.

greet.htmlTEXT
<% 
$name = “Shilan”;
ECHO "Hello "
echo $Name;
%>
Show answerوەڵامەکە پیشان بدە
  1. The file must be called greet.php, not greet.html.
  2. <% %> tags were removed in PHP 7: use <?php ?>.
  3. Curly quotes around Shilan: use straight quotes.
  4. The semicolon after ECHO "Hello " is missing. (ECHO in capitals is fine.)
  5. $Name is not the same variable as $name: variable names are case-sensitive.
  1. دەبێت ناوی greet.php بێت، نەک greet.html.
  2. <% %> لە ⁦PHP 7⁩دا لابران: <?php ?> بەکار بهێنە.
  3. نیشانەی چەماوە لە دەوری Shilan: نیشانەی ڕاست بەکار بهێنە.
  4. دوای ECHO "Hello " ونە. (ECHO بە پیتی گەورە کێشە نییە.)
  5. $Name هەمان $name نییە: ناوی هەستیارن بە پیتی گەورە و بچووک.
greet.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$name = "Shilan";
ECHO "Hello ";
echo $name;
?>
ExerciseڕاهێنانComment a scriptلێدوان بۆ دەسنووسێک بنووسە

Add comments to this script: a multi-line comment at the top with your name and the date, a single-line // comment that explains line 3, and a # comment that switches off line 4.

بۆ ئەم زیاد بکە: فرەدێڕ لە سەرەوە بە ناو و بەرواری خۆت، تاکەدێڕی // کە دێڕی 3 ڕوون بکاتەوە و # کە دێڕی 4 بکوژێنێتەوە.

PHP
<?php
echo "Welcome to the library. ";
echo "Today is " . date("l") . ". ";
echo "Closed for maintenance.";
Show answerوەڵامەکە پیشان بدە
library.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
/*
   Library welcome page
   Written by: Aram, 16 October 2026
*/
echo "Welcome to the library. ";
// Show the name of today's day, for example "Friday"
echo "Today is " . date("l") . ". ";
# echo "Closed for maintenance.";

Summaryپوختە

  • Files with PHP code must end in .php. The web server gives them to PHP; .html files are sent unchanged.
  • PHP code goes between <?php and ?>. A page can have many PHP sections, anywhere in the HTML.
  • Use only <?php ... ?> (and <?= ... ?> for short output). ASP-style and script tags were removed in PHP 7; short <? ?> tags depend on short_open_tag in php.ini.
  • A statement is one instruction. Simple statements end with a semicolon, the instruction separator. Blocks in { } need no semicolon after }.
  • Keywords, constructs and function names are not case-sensitive; variable and constant names are.
  • Comments: // and # for one line, /* */ for many lines. PHP ignores them, and they never reach the browser.
  • echo and print are language constructs, not functions. die/exit have been functions since PHP 8.4.
  • Always type code with straight quotes.
  • خاوەن کۆدی PHP دەبێت بە .php کۆتایی بێت. دەیانداتە PHP؛ .html وەک خۆیان دەنێردرێن.
  • کۆدی PHP لە نێوان <?php و ?>دا دادەنرێت. لاپەڕەیەک دەتوانێت چەندین کەرتی PHPـی هەبێت، لە هەر شوێنێکی HTMLـدا.
  • تەنها <?php ... ?> بەکار بهێنە (و <?= ... ?> بۆ کورت). شێوەی ASP و script لە ⁦PHP 7⁩دا لابران؛ کورتی <? ?> بەستراوەتەوە بە short_open_tag لە ⁦php.ini⁩ـدا.
  • یەک ڕێنماییە. سادەکان بە کۆتاییان دێت، کە . بلۆکەکانی ناو { } لەدوای } ناوێت.
  • ، و ناوی هەستیار نین؛ ناوی و هەستیارن.
  • : // و # بۆ یەک دێڕ، /* */ بۆ چەند دێڕێک. PHP فەرامۆشیان دەکات و هەرگیز ناگەنە .
  • echo و print ، نەک . die/exit لە ⁦PHP 8.4⁩ـەوە بوون بە .
  • هەمیشە کۆد بە ڕاست بنووسە.

Review questions

پرسیارەکانی پێداچوونەوە

Review questionsپرسیارەکانی پێداچوونەوە
What is a PHP statement, and what is a PHP script?ڕستەی PHP چییە و دەسنووسی PHP چییە؟

A statement is one instruction that tells the computer to do something, such as echo "Kurdistan";. A script is a file made of one or more statements.

یەک ڕێنماییە کە بە دەڵێت کارێک بکات، وەک echo "Kurdistan";. کە لە یەک یان چەند پێکدێت.

Why is the semicolon called the instruction separator?بۆچی بە خاڵبۆر دەگوترێت جیاکەرەوەی ڕێنمایی؟

Because it marks where one instruction ends and the next one begins. PHP reads a statement until it meets the semicolon.

چونکە دیاری دەکات ڕێنماییەک لە کوێ کۆتایی دێت و دواتر لە کوێ دەست پێدەکات. PHP دەخوێنێتەوە تا دەگاتە .

Is PHP case-sensitive?ئایا PHP هەستیارە بە پیتی گەورە و بچووک؟

Partly. Keywords (echo, if) and function names are not; variable names ($city vs $CITY) and constant names are.

بە بەشێک. (echo، if) و ناوی نا؛ ناوی ($city و $CITY) و ناوی بەڵێ.

What is a language construct? Give three examples.پێکهاتەی زمان چییە؟ سێ نموونە بهێنەوە.

A word built into the PHP language with a fixed meaning, which PHP recognises directly and which you do not call like a normal function, e.g. echo, print, isset (also empty, include, require).

وشەیەکە لەناو زمانی PHPـدا دروست کراوە و واتایەکی جێگیری هەیە، PHP ڕاستەوخۆ دەیناسێتەوە و وەک ئاسایی بانگی ناکەیت، وەک echo، print، isset (هەروەها empty، include، require).

What is the difference between a PHP comment and an HTML comment?جیاوازیی نێوان لێدوانی PHP و لێدوانی HTML چییە؟

A PHP comment (//, #, /* */) is removed on the server and never reaches the browser. An HTML comment (<!-- -->) is sent to the browser and anyone can read it with View Source.

PHP (//، #، /* */) لەسەر لادەبرێت و هەرگیز ناگاتە . HTML (<!-- -->) دەنێردرێت بۆ و هەرکەسێک دەتوانێت بە ⁦View Source⁩ بیخوێنێتەوە.

Videoڤیدیۆ

Watch a videoسەیری ڤیدیۆیەک بکە

A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.

3 | Learn About PHP Syntax for Beginners | 2023 | Learn PHP Full Course for BeginnersDani Krossing · Englishئینگلیزی · 197K viewsبینین · 3.2K likesلایک

The basic rules of PHP in 7 minutes: PHP tags, semicolons, pure PHP files without a closing tag, PHP inside HTML, and comments.

بنەماکانی لە 7 خولەکدا: ، ، بەبێ داخستن، لەناو و .

Whole video: tags, semicolons, embedding and comments

هەموو ڤیدیۆکە: ، ، و .

Lesson complete!وانەکە تەواو بوو!

Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.

Key termsزاراوە سەرەکییەکان

Next lessonوانەی داهاتوو

Output with echo and printدەرخستە بە echo و print

References and further readingسەرچاوەکان و خوێندنەوەی زیاتر

This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.