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، ، و ، هەستیاری بە پیتی گەورە و بچووک، و .
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 لە کوێ دادەنرێت، چۆن دەست پێدەکات و کۆتایی دێت، چۆن کۆتاییان دێت، کام ناوانە گرنگی بە پیتی گەورە دەدەن و چۆن دەنووسرێت.
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ـدا دابنرێت: پێشی، دوای، یان لە ناوەڕاستی دێڕێکدا.
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 دەنووسیت:
<?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ـیان لە نێواندا بێت یان نا. ئەم نموونەیەی تێبینییە کوردییەکان دوو کەرتی هەیە و هەر یەکەیان وشەیەک دەنووسێت:
<?php
echo "Kurd 1";
?>
<?php
echo "Kurd 2";
?>Kurd 1Kurd 2
Why is there no new line between them? PHP removes one line break that comes directly after ?>. So the line break after the first ?> is not printed.
بۆچی هیچ دێڕێکی نوێ لە نێوانیاندا نییە؟ PHP یەک دێڕبڕین کە ڕاستەوخۆ لەدوای ?> دێت لادەبات. بۆیە دێڕبڕینەکەی دوای یەکەم ?> نانووسرێت.
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ـی ئاساییدان، بەم شێوەیە:
<!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>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<p>This line was written by PHP.</p>
<p>This line is plain HTML.</p>
<p>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 لە هەمان لاپەڕەدا.
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. سلایدەکان چوار شێوەی پیشان دەدەن. تەنها هەندێکیان هێشتا کار دەکەن:
| 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 چی دەنێرێت:
<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>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<p>1: 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>Lines 3 and 4 did not run. The browser shows “3: <% echo "ASP-style tag"; %>” as text and hides the script element, but View Source shows all the PHP code.
دێڕەکانی 3 و 4 جێبەجێ نەبوون. «3: <% echo "ASP-style tag"; %>» وەک دەق پیشان دەدات و script دەشارێتەوە، بەڵام View Source هەموو کۆدی PHPـەکە پیشان دەدات.
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ـی ناویان دەنێردرێت بۆ سەردانیکەر!
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).
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 دەخاتە سەر :
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 هەر دەخوێنێتەوە تا دەگاتە . دوو لەدوای یەک:
<?php
echo "Kurdistan";
echo "Erbil";
?>KurdistanErbil
echo adds no space or new line by itself, so the two words are joined.
echo خۆی هیچ یان دێڕێکی نوێ زیاد ناکات، بۆیە دوو وشەکە پێکەوە نووسراون.
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2-3
Each
echostatement 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 ئیتر نازانێت ڕێنمایی یەکەم لە کوێ کۆتایی دێت، بۆیە بە ڕادەوەستێت:
<?php
echo "Kurdistan"
echo "Erbil";
?>Parse error: syntax error, unexpected token "echo", expecting "," or ";" in semicolon.php on line 3
PHP prints the full path of the file in its messages; here we show only the file name.
PHP لە پەیامەکانیدا تەواوی دەنووسێت؛ لێرەدا تەنها ناوی داناوە.
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دایە. هەمیشە سەیری دێڕی پێشەوەش بکە. ئەگەر ئەو نییە دوایین بێت لە ، پەیامەکە جیاوازە:
<?php
echo "Kurdistan"Parse error: syntax error, unexpected end of file, expecting "," or ";" in semicolon2.php on line 3
The message names line 3, although the code has only two lines. Code editors end a file with a line break, so the end of the file is on line 3, and that is where PHP noticed the problem. (PHP prints the full path of the file; here we show only the file name.)
پەیامەکە ناوی دێڕی 3 دەبات، هەرچەندە کۆدەکە تەنها دوو دێڕە. دەستکاریکەرەکانی کۆد بە دێڕبڕینێک کۆتایی پێدەهێنن، بۆیە کۆتایی لە دێڕی 3دایە و PHP لەوێ کێشەکەی بینی. (PHP تەواوی دەنووسێت؛ لێرەدا تەنها ناوی داناوە.)
Statements and the semicolonڕستە و خاڵبۆر
A semicolon before ?> is optionalخاڵبۆر پێش ?> ئارەزوومەندانەیە
The closing tag ?> ends a statement by itself, so this line works without a semicolon:
داخستنی ?> خۆی کۆتایی پێدەهێنێت، بۆیە ئەم دێڕە بەبێ کار دەکات:
<?php echo "Kurdistan" ?>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 بەدوای دەگەڕێت، نەک بەدوای کۆتایی دێڕدا. بۆیە یەک دەتوانێت چەند دێڕێک بگرێتەوە و ئەمە کار دەکات (بەڵام خوێندنەوەی قورسە):
<?php
echo "Erbil" ;
echo
" and "
;
echo "Duhok";Erbil and Duhok
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3-5
One
echostatement 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) یان . لەدوای کەوانەی داخستنی}نییە، بەڵام سادەکانی ناو کەوانەکان هێشتا پێویستیان بە هەیە.
<?php
$time = "night";
if ($time == "night") {
echo "Pray";
}Pray
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
A simple statement: it stores the text
nightin the variable$time. You will learn variables in Variables.سادە: دەقی
nightلە$timeدا هەڵدەگرێت. لە وانەی گۆڕاوەکان فێر دەبیت.- Lineدێڕی 3
ifstarts 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
}.لەدوای
}نییە.
Statements and the semicolonڕستە و خاڵبۆر
Language constructsپێکهاتەکانی زمان
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 ڕاستەوخۆ دەیناسێتەوە، بۆیە وەک ئاسایی بانگی ناکەیت و زۆربەیان پێویستیان بە کەوانە نییە. ئەمانە یان کاری بنەڕەتی دەکەن، وەک نووسینی دەق، یان پێکهاتەی کۆدەکە دروست دەکەن.
| 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 نەک ، دەتوانیت بە کەوانە یان بەبێ کەوانە بینووسیت و ناتوانیت بە شێوەکانی تر وەک بەکاری بهێنیت. ئەم نموونەیە جیاوازییەکە پیشان دەدات:
<?php
echo "Hello", " ", "World";
echo ("!");
$f = "strtoupper";
echo $f(" erbil");
$g = "echo";
$g(" duhok");Hello World! ERBIL
Fatal error: Uncaught Error: Call to undefined function echo() in construct.php:7
Stack trace:
#0 {main}
thrown in construct.php on line 7PHP prints the full path of the file in its messages; here we show only the file name.
PHP لە پەیامەکانیدا تەواوی دەنووسێت؛ لێرەدا تەنها ناوی داناوە.
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
echowith three items and no parentheses.echoبە سێ بڕگە و بەبێ کەوانە.- Lineدێڕی 3
Parentheses are allowed around one value, but they are not a function call.
کەوانە لە دەوری یەک ڕێگەپێدراوە، بەڵام نییە.
- Lineدێڕی 4-5
strtoupperis a real function, so PHP can call it through a variable that holds its name.strtoupperڕاستەقینەیە، بۆیە PHP دەتوانێت لە ڕێگەی کە ناوەکەی تێدایە بانگی بکات.- Lineدێڕی 6-7
echois not a function, so the same trick fails with an error.echoنییە، بۆیە هەمان فێڵ بە سەرناکەوێت.
<?php
echo "Before exit. ";
exit("Goodbye.");
echo "This line never runs.";Before exit. Goodbye.
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.
ئەم دێڕە هەرگیز جێبەجێ نابێت.
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 «زۆربەیان هەستیار نین». ئەمە ڕاستە، بەڵام هەڵاوێردەی گرنگ هەن:
| 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 بەکار دەهێنێت. هەر سێکیان کار دەکەن:
<?php
echo "<p>Explore <strong>Africa</strong>, <br />";
Echo "<strong>South America</strong>, <br />";
ECHO " and <strong>Australia</strong>!</p>";
?>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<p>Explore <strong>Africa</strong>, <br /><strong>South America</strong>, <br /> 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:
نموونەکەی کورتەکەش هەمان وشە سێ جار دەنووسێت:
<?php
Echo "Hello";
EChO "Hello";
echo "Hello";HelloHelloHello
Function names are not case-sensitive either, and neither are keywords such as if:
ناوی هەستیار نین، هەروەها وەک if:
<?php
echo strtoupper("erbil "), STRTOUPPER("duhok "), StrToUpper("zakho");
IF (true) {
ECHO "<br>Keywords work in any case.";
}ERBIL DUHOK ZAKHO Keywords work in any case.
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
ERBIL DUHOK ZAKHO<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
IFandECHOin 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 دوو جیاوازن:
<?php
$city = "Erbil";
echo $city;
echo $CITY;Erbil Warning: Undefined variable $CITY in vars.php on line 4
PHP prints the full path of the file in its messages; here we show only the file name.
PHP لە پەیامەکانیدا تەواوی دەنووسێت؛ لێرەدا تەنها ناوی داناوە.
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
Create the variable
$city.$cityدروست بکە.- Lineدێڕی 4
$CITYis 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دا نەناسراو :
<?php
define("CITY", "Sulaimani");
echo CITY;
echo city;Sulaimani
Fatal error: Uncaught Error: Undefined constant "city" in constants.php:4
Stack trace:
#0 {main}
thrown in constants.php on line 4PHP prints the full path of the file in its messages; here we show only the file name.
PHP لە پەیامەکانیدا تەواوی دەنووسێت؛ لێرەدا تەنها ناوی داناوە.
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
define()creates the constantCITY. Constants are explained in Constants and scope.define()CITYدروست دەکات. لە وانەی نەگۆڕ و مەودا ڕوون کراونەتەوە.- Lineدێڕی 4
cityin small letters is another name, which does not exist.cityبە پیتی بچووک ناوێکی ترە کە بوونی نییە.
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 دوو جۆر هەیە:
| 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.ڕوونکردنەوەی درێژتر، بۆ نموونە چۆنیەتی کارکردنی . دەتوانێت هەر ژمارەیەک دێڕ بگرێتەوە. |
<?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
?>Kurd
Only echo produced output. PHP ignored all the comments.
تەنها echo دروست کرد. PHP هەموو فەرامۆش کرد.
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:
ئەمانە نموونەکانی هەروەک سلاید و تێبینییە کوردییەکان داویانن:
<?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 commentKurd
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ـە:
<p><?php echo "A"; // this comment ends here ?> B</p>A B
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<p>A 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 بە ڕادەوەستێت.
<?php
/* outer comment
/* inner comment */
this line is no longer inside a comment
*/
echo "done";Parse error: syntax error, unexpected identifier "line" in nested.php on line 4
PHP prints the full path of the file in its messages; here we show only the file name.
PHP لە پەیامەکانیدا تەواوی دەنووسێت؛ لێرەدا تەنها ناوی داناوە.
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)، نەک . بۆیە دێڕێک کە بە #[ دەست پێبکات وەک کۆد دەخوێنرێتەوە:
<?php
#[This looks like a comment]
echo "Hello";Parse error: syntax error, unexpected identifier "looks", expecting "]" in attribute.php on line 2
PHP prints the full path of the file in its messages; here we show only the file name.
PHP لە پەیامەکانیدا تەواوی دەنووسێت؛ لێرەدا تەنها ناوی داناوە.
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 لەسەر لادەبرێت و هەرگیز لەوێ دەرناچێت.
<!-- HTML comment: the browser receives this -->
<?php // PHP comment: the browser never receives this ?>
<p>Hello</p>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<!-- HTML comment: the browser receives this -->
<p>Hello</p>The HTML comment reached the browser; the PHP comment did not.
HTML گەیشتە ؛ PHP نەگەیشت.
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.”
کۆدەکە خۆی دەڵێت چی دەکات. باش دەڵێت بۆچی بەو شێوەیە کردووتە. سلایدەکان پێی دەڵێن: «هۆکار بنووسە، نەک کارەکە.»
<?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 chargeYou 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:
دەتوانیت بۆ دۆزینەوەی بەکار بهێنیت. // بخەرە پێش دێڕێک بۆ ئەوەی بۆ ماوەیەک بیکوژێنیتەوە، پاشان لاپەڕەکە دووبارە کار پێبکەرەوە:
<?php
echo "Line 1 ";
// echo "Line 2 ";
echo "Line 3";Line 1 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.
خودی کەرەستەکانی کۆرسەکە هەندێک لەم هەڵانەیان تێدایە. فێر ببە بیانناسیتەوە.
| Mistake | What 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 بە نیشانەی چەماوە چاپ کرابوو. ئەگەر وەک خۆی کۆپی بکرێت، سەرناکەوێت:
<?php
// Displaying H
echo “Hello World”;
?>Parse error: syntax error, unexpected identifier "World”", expecting "," or ";" in lab1-ex2-as-printed.php on line 3
PHP prints the full path of the file in its messages; here we show only the file name.
PHP لە پەیامەکانیدا تەواوی دەنووسێت؛ لێرەدا تەنها ناوی داناوە.
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” وەک ناوی دەخوێنێتەوە:
Fatal error: Uncaught Error: Undefined constant "“Kurdistan”" in kurdistan.php:2
Stack trace:
#0 {main}
thrown in kurdistan.php on line 2PHP prints the full path of the file in its messages; here we show only the file name.
PHP لە پەیامەکانیدا تەواوی دەنووسێت؛ لێرەدا تەنها ناوی داناوە.
Practiceڕاهێنان
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وەڵامەکە پیشان بدە
<?php
// Displaying Hello World
echo "Hello World";
?>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»ـە.
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 تێیدا تێکچوو؛ ڕاستەقینەکە لەوانەیە لەو دێڕەدا بێت یان لە دێڕی پێشتر.
Find and fix five mistakes in this script. Then write what it prints.
پێنج لەم بدۆزەرەوە و چاکیان بکە. پاشان بنووسە چی دەنووسێت.
<%
$name = “Shilan”;
ECHO "Hello "
echo $Name;
%>Show answerوەڵامەکە پیشان بدە
- The file must be called
greet.php, notgreet.html. <% %>tags were removed in PHP 7: use<?php ?>.- Curly quotes around Shilan: use straight quotes.
- The semicolon after
ECHO "Hello "is missing. (ECHOin capitals is fine.) $Nameis not the same variable as$name: variable names are case-sensitive.
- دەبێت ناوی
greet.phpبێت، نەکgreet.html. -
<% %>لە PHP 7دا لابران:<?php ?>بەکار بهێنە. - نیشانەی چەماوە لە دەوری Shilan: نیشانەی ڕاست بەکار بهێنە.
- دوای
ECHO "Hello "ونە. (ECHOبە پیتی گەورە کێشە نییە.) $Nameهەمان$nameنییە: ناوی هەستیارن بە پیتی گەورە و بچووک.
<?php
$name = "Shilan";
ECHO "Hello ";
echo $name;
?>Hello Shilan
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
echo "Welcome to the library. ";
echo "Today is " . date("l") . ". ";
echo "Closed for maintenance.";Show answerوەڵامەکە پیشان بدە
<?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.";Welcome to the library. Today is Friday.
The day name depends on when you run it.
ناوی ڕۆژەکە بەستراوەتەوە بەوەی کەی کاری پێدەکەیت.
Summaryپوختە
- Files with PHP code must end in
.php. The web server gives them to PHP;.htmlfiles are sent unchanged. - PHP code goes between
<?phpand?>. 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 onshort_open_tagin 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. echoandprintare language constructs, not functions.die/exithave 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
پرسیارەکانی پێداچوونەوە
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.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.
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زاراوە سەرەکییەکان
Output with echo and printدەرخستە بە echo و print
Related lecturesوانە پەیوەندیدارەکان
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.