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

Strings and string functionsزنجیرەنووسەکان و کردارەکانی زنجیرەنووسە

How to write strings with single and double quotes, join them with the dot, and use PHP's string functions (strlen, trim, str_replace, strpos, substr, explode, md5, htmlspecialchars and more). Every course example is run and corrected.

چۆن بە تاکەگوتە و جووتەگوتە بنووسیت، بە خاڵ پێکەوەیان بلکێنیت و PHP بەکاربهێنیت (strlen، trim، ⁦str_replace⁩، strpos، substr، explode، ⁦md5⁩، htmlspecialchars و زیاتر). هەموو نموونەیەکی کۆرسەکە تاقی کراوەتەوە و ڕاست کراوەتەوە.

35 min read35 خولەک خوێندنەوە · 36 stepsهەنگاو

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

  • Write strings with single and double quotes (and as heredoc or nowdoc) and explain how they differ.
  • Use escape sequences such as \n, \t and \" correctly.
  • Join strings with the dot . and add to a string with .=.
  • Use the common string functions and predict their results, counting positions from 0.
  • Avoid the classic traps: trim() in the middle, strpos() returning 0, and md5() for passwords.
  • Print user text safely with htmlspecialchars().
  • بە تاکەگوتە و جووتەگوتە (و وەک یان nowdoc) بنووسیت و جیاوازییەکەیان ڕوون بکەیتەوە.
  • وەک \n، \t و \" بە دروستی بەکاربهێنیت.
  • بە خاڵ . پێکەوە بلکێنیت و بە .= شت بخەیتە سەر .
  • بەکاربهێنیت و ئەنجامەکانیان پێشبینی بکەیت، بە ژماردنی شوێنەکان لە 0ـەوە.
  • خۆت لە تەڵە باوەکان بپارێزیت: trim() لە ناوەڕاستدا، گەڕاندنەوەی 0 لە strpos() و md5() بۆ .
  • دەقی بە سەلامەتی بە htmlspecialchars() چاپ بکەیت.

Why strings matterبۆچی زنجیرەنووسەکان گرنگن

Almost everything a web page shows is text: names, messages, menus, and even the HTML code itself. In PHP, a piece of text is called a . In this lecture you learn how to write strings, how to join them, and how to use PHP's to measure, search, cut, change and protect text.

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

A is a sequence of : letters, digits, spaces and symbols. A string can be any text inside quotes. You can use single quotes ('Hello') or double quotes ("Hello"). PHP has many tools for working with strings.

زنجیرەیەکە لە : پیت، ژمارە، و هێما. دەکرێت هەر دەقێک بێت کە لەناو نیشانەی گوتەدا نووسرابێت. دەتوانیت تاکەگوتە ('Hello') یان جووتەگوتە ("Hello") بەکاربهێنیت. PHP ئامرازی زۆری هەیە بۆ کارکردن لەگەڵ .

Definitionپێناسە

A sequence of characters, such as a word or a sentence, written inside single or double quotes: 'Hello' or "Hello". A number inside quotes, like "42", is also a string.

کۆمەڵێک نووسەیە (پیت، ژمارە، بۆشایی یان هێما) کە لەناو تاکە یان جووتە نیشانەی گوتە دەنووسرێت، وەک 'Hello' یان "Hello". ژمارەیەک لەناو نیشانەی گوتە، وەک "42"، ئەویش هەر زنجیرەنووسەیە.

Definitionپێناسە

One letter, digit, space or symbol in a piece of text. A is a row of characters, and each character has a position () that starts from 0.

یەک پیت، ژمارە، بۆشایی یان هێما لە پارچە دەقێکدا. ڕیزێکە لە نووسە و هەر نووسەیەک شوێنێکی () هەیە کە لە 0ـەوە دەست پێ دەکات.

A string is like a tasbihزنجیرەنووسە وەک تەزبیح

Think of a string as a tasbih (a string of prayer beads). Each bead is one character, and the beads stay in a fixed order. PHP numbers the beads from the left, and the first bead has the number 0.

وەک تەزبیحێک وایە. هەر دەنکێک و دەنکەکان بە ڕیزبەندییەکی جێگیر داندراون. PHP دەنکەکان لە چەپەوە ژمارە دەکات و یەکەم دەنک ژمارە 0ـی هەیە.

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

The beads of a tasbih are all alike, but characters can be letters, spaces or symbols. Also, PHP can cut, copy or replace part of the row in one step, which you cannot do with real beads.

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

Writing stringsنووسینی زنجیرەنووسەکان

You write a string by putting text between two quote marks of the same kind. The quote marks are not part of the string. PHP needs straight quotes (' or "). Curly quotes (“ ” ‘ ’), which word processors add automatically, cause errors.

بەوە دەنووسیت کە دەقەکە لە نێوان دوو نیشانەی گوتەی هاوجۆردا دابنێیت. بەشێک نین لە . PHP نیشانەی گوتەی ڕاستی پێویستە (' یان "). نیشانەی گوتەی چەماوە (“ ” ‘ ’)، کە نەرمەکاڵاکانی نووسین خۆکارانە دایدەنێن، دروست دەکەن.

PHP String Data Type - Heredoc & Nowdoc Syntax - Full PHP 8 TutorialProgram With Gio · Englishئینگلیزی · 82K viewsبینین · 3K likesلایک

Learn single- and double-quoted strings, then how heredoc and nowdoc let you write a long text over many lines.

فێری و دەبیت، پاشان دەبینیت چۆن و nowdoc ڕێگەت پێدەدەن دەقێکی درێژ لە چەند دێڕێکدا بنووسیت.

Whole video: quotes, variables in strings, heredoc and nowdoc.

هەموو ڤیدیۆکە: گوتەکان، لەناو ، و nowdoc.

Writing stringsنووسینی زنجیرەنووسەکان

HTML tags inside stringsتاگەکانی HTML لەناو زنجیرەنووسەکاندا

A string can contain HTML . PHP does not read the tags. It simply sends them to the , and the browser draws them. In the example below, <br /> starts a new line on the page.

دەتوانێت HTML لەخۆ بگرێت. PHP ناخوێنێتەوە، تەنها دەیاننێرێت بۆ ، ئینجا دەیانکێشێت. لە نموونەی خوارەوەدا <br /> دێڕێکی نوێ لەسەر لاپەڕەکە دەست پێ دەکات.

Strings, HTML tags and the dotزنجیرەنووسەکان، تاگەکانی HTML و خاڵhello.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "Hello World <br />";
echo 'Hello World <br />';
$my_variable = "Hello World";
echo $my_variable;
echo $my_variable . " Again";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

A double-quoted string with an HTML tag inside.

لەناو جووتەگوتەدا کە HTML تێدایە.

Lineدێڕی 3

The same text in single quotes. With no variable inside, both quotes give the same result.

هەمان دەق لەناو تاکەگوتەدا. کاتێک هیچ تێدا نییە، هەردوو جۆری گوتە هەمان ئەنجام دەدەن.

Lineدێڕی 4

A can hold a string.

دەتوانێت هەڵبگرێت.

Lineدێڕی 5-6

Line 5 prints no <br />, so line 6 continues on the same line. The dot (.) joins the variable and the text " Again".

دێڕی 5 هیچ <br />ـێک چاپ ناکات، بۆیە دێڕی 6 لەسەر هەمان دێڕ بەردەوام دەبێت. خاڵ (.) و دەقی " Again" پێکەوە دەلکێنێت.

To put every part on its own line, print a <br /> after the third echo as well:

بۆ ئەوەی هەر بەشێک لەسەر دێڕی خۆی بێت، دوای echoـی سێیەمیش <br /> چاپ بکە:

hello.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "Hello World <br />";
echo 'Hello World <br />';
$my_variable = "Hello World";
echo $my_variable . "<br />";
echo $my_variable . " Again";
?>

Writing stringsنووسینی زنجیرەنووسەکان

Single quotes or double quotes?تاکەگوتە یان جووتەگوتە؟

Single vs double quotesتاکەگوتە بەرامبەر جووتەگوتەquotes.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$variable = "name";
$literally = 'My $variable will not print!';
print($literally);
// My $variable will not print!
echo "<br>";
$literally = "My $variable will print!";
print($literally);
// My name will print!
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

Single quotes: $variable stays as plain text.

تاکەگوتە: $variable وەک دەقێکی ئاسایی دەمێنێتەوە.

Lineدێڕی 6

Added so the two results appear on separate lines.

زیاد کراوە بۆ ئەوەی دوو ئەنجامەکە لەسەر دوو دێڕی جیا دەربکەون.

Lineدێڕی 7

Double quotes: PHP puts the value name in place of $variable.

جووتەگوتە: PHP name لە جێگەی $variable دادەنێت.

Replacing a variable with its value inside double quotes is called . It works only in double quotes (and in heredoc text, see Long strings: heredoc and nowdoc).

دانانی لە جێگەی ناوەکەی لەناو جووتەگوتەدا پێی دەوترێت . ئەمە تەنها لەناو جووتەگوتەدا کار دەکات (هەروەها لە دەقی ، بڕوانە زنجیرەنووسەکانی درێژ: Heredoc و nowdoc).

Definitionپێناسە

Putting a variable directly inside a so that PHP replaces it with its value: "Hi $name". Use curly braces when letters follow the name: "{$type}cage".

دانانی گۆڕاو ڕاستەوخۆ لەناو ، تاکو PHP نرخەکەی لە جێی دابنێت: "Hi $name". ئەگەر پیت دوای ناوەکە هات، کەوانەی لوولی بەکاربهێنە: "{$type}cage". ئەم کارە ناکەن.

Two rows. Top: echo with single quotes around 'Hello, $name!' prints Hello, $name! unchanged. Bottom: echo with double quotes around "Hello, $name!": PHP finds $name, puts in its value Aram, and prints Hello, Aram!دوو بەش. سەرەوە: echo لەگەڵ تاکەگوتە لە دەوری 'Hello, $name!' بێ گۆڕان Hello, $name! چاپ دەکات. خوارەوە: echo لەگەڵ جووتەگوتە: PHP ناوی $name دەدۆزێتەوە، Aram لە جێگەی دادەنێت و Hello, Aram! چاپ دەکات.
With single quotes the text is printed as written. With double quotes PHP first replaces each with its .بە تاکەگوتە دەقەکە وەک خۆی چاپ دەکرێت. بە جووتەگوتە PHP سەرەتا هەر بە دەگۆڕێت.CêIT
Quick checkپشکنینی خێراWhat is the difference between single and double quotes?جیاوازیی نێوان تاکەگوتە و جووتەگوتە چییە؟

Writing stringsنووسینی زنجیرەنووسەکان

More about quotes and variablesزیاتر دەربارەی گوتە و گۆڕاوەکان

A keeps its value until the end of the , even across several <?php ... ?> blocks in the same file. Here the variable is set in the first block and printed inside double quotes in the second block:

تا کۆتایی خۆی دەپارێزێت، تەنانەت ئەگەر لە چەند بلۆکێکی <?php ... ?>ـی هەمان بێت. لێرەدا لە بلۆکی یەکەمدا دانراوە و لە بلۆکی دووەمدا لەناو جووتەگوتەدا چاپ دەکرێت:

again.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$my_variable = "Hello World";
?>
<?php
echo "$my_variable Again.";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

First PHP block: create the variable.

بلۆکی یەکەمی PHP: دروستکردنی .

Lineدێڕی 5

Second PHP block: the variable still exists, and double quotes put its value into the text.

بلۆکی دووەمی PHP: هێشتا هەیە و جووتەگوتە دەخاتە ناو دەقەکەوە.

HTML tags work in both kinds of quotes. Only the variable behaves differently:

HTML لە هەردوو جۆری گوتەدا کار دەکەن. تەنها جیاوازە:

bold.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$friend = "Shilan";
$j = "<b>Bold</b> $friend";
$i = '<b>Bold</b> $friend';
echo $j;
echo "<br>";
echo $i;
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

Double quotes: $friend becomes Shilan.

جووتەگوتە: $friend دەبێت بە Shilan.

Lineدێڕی 4

Single quotes: $friend stays as it is. The <b> tag still makes the word bold.

تاکەگوتە: $friend وەک خۆی دەمێنێتەوە. <b> هێشتا وشەکە تۆخ دەکات.

Lineدێڕی 6

Added: without it the two results would run together.

زیاد کراوە: بەبێ ئەمە دوو ئەنجامەکە بە یەکەوە دەنووسێن.

Single and double quotes comparedبەراوردی تاکەگوتە و جووتەگوتە
FeatureبابەتSingle quotes '...'تاکەگوتە '...'Double quotes "..."جووتەگوتە "..."
Variables like $name are replaced by their value وەک $name بە خۆیان دەگۆڕدرێنNoنەخێرYesبەڵێ
The \n and \t work وەک \n و \t کار دەکەنNo (only \' and '\\')نەخێر (تەنها \' و '\\')Yesبەڵێ
HTML tags work HTML کار دەکەنYesبەڵێYesبەڵێ
Good forباشە بۆFixed text that should not changeدەقی جێگیر کە نابێت بگۆڕێتText that contains variablesدەقێک کە تێدایە

Writing stringsنووسینی زنجیرەنووسەکان

Escape sequencesهێما تایبەتەکان

Some characters are hard to type inside a string: a new line, a tab, or the quote mark that ends the string. For these, PHP uses an : a backslash followed by a character, for example \n. Double quotes understand many escape sequences. Single quotes understand only two: \' (a single quote) and '\\' (one backslash).

هەندێک بە ئاسانی لەناو نانووسرێن: دێڕی نوێ، تاب، یان ئەو نیشانەی گوتەیەی کۆتایی پێ دەهێنێت. بۆ ئەمانە PHP بەکاردەهێنێت: لارەهێڵی پێچەوانە و دوای ئەویش ، بۆ نموونە \n. جووتەگوتە زۆر دەناسێتەوە. تاکەگوتە تەنها دووان دەناسێتەوە: \' (تاکەگوتەیەک) و '\\' (یەک لارەهێڵی پێچەوانە).

Definitionپێناسە

A backslash plus a character that has a special meaning inside a string, such as \n (new line), \t (tab) or \" (a double quote). In PHP they work only in double-quoted strings, and \n breaks the line in the HTML source, not on the web page.

هێمای \ لەگەڵ نووسەیەک کە لەناو واتایەکی تایبەتی هەیە، وەک \n (دێڕی نوێ)، \t ⁦(tab)⁩ یان \" (نیشانەی گوتەی جووت). لە PHPـدا تەنها لە کار دەکەن و \n دێڕ لە کۆدی HTMLـدا دەشکێنێت، نەک لەسەر لاپەڕەی وێب.

Common escape sequencesباوترین
SequenceهێماMeaningواتاIn double quotesلە جووتەگوتەداIn single quotesلە تاکەگوتەدا
\nNew lineدێڕی نوێWorksکار دەکاتPrinted as \nوەک \n چاپ دەبێت
\tTabتابWorksکار دەکاتPrinted as \tوەک \t چاپ دەبێت
\rCarriage returnگەڕانەوە بۆ سەرەتای دێڕWorksکار دەکاتPrinted as \rوەک \r چاپ دەبێت
\$A real dollar sign, not a variableنیشانەی دۆلاری ڕاستەقینە، نەک Worksکار دەکاتPrinted as \$وەک \$ چاپ دەبێت
\"A double quoteجووتەگوتەیەکWorksکار دەکاتPrinted as \"وەک \" چاپ دەبێت
\'A single quoteتاکەگوتەیەکNot an escape: prints \' نییە: \' چاپ دەکاتWorksکار دەکات
\\One backslashیەک هێڵی لارWorksکار دەکاتWorksکار دەکات
More escape sequencesهێما تایبەتەکانی زیاترescapes.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$price = 5000;
echo "Line 1\nLine 2<br>";
echo "Price: \$price = $price dinars<br>";
echo "She said \"Hello\"<br>";
echo 'It\'s Aram\'s book<br>';
echo 'One backslash: \\<br>';
echo 'No new line here: \n';
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

\n makes a new line in the HTML that PHP sends, but the browser shows it as a space.

\n لەو HTMLـەی PHP دەینێرێت دێڕی نوێ دروست دەکات، بەڵام وەک پیشانی دەدات.

Lineدێڕی 4

\$price prints the dollar sign and the name; $price prints the value.

\$price نیشانەی دۆلار و ناوەکە چاپ دەکات؛ $price چاپ دەکات.

Lineدێڕی 5

\" puts a double quote inside a double-quoted string.

\" جووتەگوتەیەک دەخاتە ناو .

Lineدێڕی 8

In single quotes \n is just two characters.

لە تاکەگوتەدا \n تەنها دوو .

Writing stringsنووسینی زنجیرەنووسەکان

Escape sequences in the course examplesهێما تایبەتەکان لە نموونەکانی کۆرسەکەدا

Lab 2, Example 4 shows the difference between the two kinds of quotes, with variables and with \t:

تاقیگەی 2، نموونەی 4 جیاوازیی هەردوو جۆری گوتە پیشان دەدات، هەم لەگەڵ و هەم لەگەڵ \t:

Lab 2, Example 4: difference between single and double quotesتاقیگەی 2، نموونەی 4: جیاوازیی تاکەگوتە و جووتەگوتەquotes2.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$my_str = 'World';
echo "Hello, $my_str!<br>";
echo 'Hello, $my_str!<br>';


echo '<pre>Hello\tWorld!</pre>';
echo "<pre>Hello\tWorld!</pre>";
echo 'I\'ll be back';
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

Double quotes: $my_str becomes World.

جووتەگوتە: $my_str دەبێت بە World.

Lineدێڕی 4

Single quotes: $my_str is printed as it is.

تاکەگوتە: $my_str وەک خۆی چاپ دەبێت.

Lineدێڕی 7

Single quotes: \t is two plain characters, a backslash and a t.

تاکەگوتە: \t دوو ئاسایین، لارەهێڵی پێچەوانە و t.

Lineدێڕی 8

Double quotes: \t becomes a real tab. <pre> keeps the tab visible in the browser.

جووتەگوتە: \t دەبێت بە تابی ڕاستەقینە. <pre> تابەکە لە دیار دەهێڵێتەوە.

Lineدێڕی 9

\' lets you put a single quote inside a single-quoted string.

\' ڕێگە دەدات تاکەگوتەیەک بخەیتە ناو .

The course summary also tests \' inside double quotes. There it is not an escape, so the backslash is printed:

پوختەی کۆرسەکە هەروەها \' لەناو جووتەگوتەدا تاقی دەکاتەوە. لەوێدا نییە، بۆیە لارەهێڵە پێچەوانەکە چاپ دەبێت:

ill-do-it.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "I\'ll do it\nH";
echo "<br>";
echo 'I\'ll do it\nH';
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

Double quotes: \' stays as \', and \n becomes a new line (shown as a space).

جووتەگوتە: \' وەک \' دەمێنێتەوە و \n دەبێت بە دێڕی نوێ (وەک پیشان دەدرێت).

Lineدێڕی 4

Single quotes: \' becomes ', and \n stays as two characters.

تاکەگوتە: \' دەبێت بە ' و \n وەک دوو دەمێنێتەوە.

Quick checkپشکنینی خێراWhich line prints a real tab between A and B?کام دێڕ تابێکی ڕاستەقینە لە نێوان A و Bـدا چاپ دەکات؟

Writing stringsنووسینی زنجیرەنووسەکان

Long strings: heredoc and nowdocزنجیرەنووسەکانی درێژ: Heredoc و nowdoc

For a long piece of text over several lines, PHP has two more ways to write a string. A starts with <<< and a name, for example <<<TEXT, and ends with the same name on its own line. It works like double quotes: variables are replaced by their values and escape sequences work. A nowdoc puts the name in single quotes (<<<'TEXT') and works like single quotes: everything is printed exactly as written.

بۆ دەقێکی درێژ کە چەند دێڕێک دەگرێتەوە، PHP دوو ڕێگەی تری بۆ نووسینی هەیە. بە <<< و ناوێک دەست پێ دەکات، بۆ نموونە <<<TEXT و بە هەمان ناو لەسەر دێڕێکی جیا کۆتایی دێت. وەک جووتەگوتە کار دەکات: بە خۆیان دەگۆڕدرێن و کار دەکەن. nowdoc ناوەکە دەخاتە ناو تاکەگوتەوە (<<<'TEXT') و وەک تاکەگوتە کار دەکات: هەموو شتێک ڕێک وەک خۆی چاپ دەکرێت.

Heredoc and nowdocHeredoc و nowdocPHP
<?php
$name = "Hana";
$city = "Erbil";

echo <<<TEXT
<p>Hello, $name!</p>
<p>Welcome to {$city}.</p>
TEXT;

echo <<<'TEXT'
<p>In a nowdoc, $name stays as it is.</p>
TEXT;
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 5

<<<TEXT starts a heredoc. The text runs until the line TEXT;.

<<<TEXT دەست پێ دەکات. دەقەکە تا دێڕی TEXT; بەردەوام دەبێت.

Lineدێڕی 6-7

As in double quotes, $name and {$city} are replaced by their values. The line break between the two lines is kept.

وەک جووتەگوتە، $name و {$city} بە خۆیان دەگۆڕدرێن. شکانی دێڕی نێوان دوو دێڕەکە دەمێنێتەوە.

Lineدێڕی 10

<<<'TEXT', with single quotes, starts a nowdoc.

<<<'TEXT'، بە تاکەگوتەوە، nowdoc دەست پێ دەکات.

Lineدێڕی 11

Nothing is replaced: $name is printed as written.

هیچ شتێک ناگۆڕدرێت: $name وەک خۆی چاپ دەکرێت.

Quick checkپشکنینی خێراWhich kind of string prints $name as it is, without replacing it?کام جۆری $name وەک خۆی چاپ دەکات، بەبێ ئەوەی بیگۆڕێت؟

Joining strings: the dot operatorپێکەوەلکاندن: کارپێکەری خاڵ

To join two strings into one, put a dot (.) between them. Joining strings is called . The dot is an , like + for numbers. It is not a .

بۆ ئەوەی دوو بکەیتە یەک، خاڵێک (.) لە نێوانیاندا دابنێ. ئەم کارە پێی دەوترێت . خاڵ ، وەک + بۆ ژمارەکان. نییە.

Definitionپێناسە

Joining strings (or lists) end to end. Python, Java and C# use +; PHP uses the dot operator . and .=.

بەیەکەوەلکاندنی (یان لیستەکان) لە دوای یەک. Python، Java و ⁦C#⁩ + بەکار دەهێنن؛ PHP کارپێکەری خاڵ . و .= بەکار دەهێنێت.

join.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$string1 = "Hello World";
$string2 = "1234";
echo $string1 . " " . $string2;
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

Three pieces are joined: the first string, a space " ", and the second string. PHP adds no space by itself.

سێ پارچە پێکەوە دەلکێنرێن: یەکەم، " " و دووەم. PHP خۆی هیچ زیاد ناکات.

The course summary lists four facts about strings. This example shows all four:

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

summary.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$my_var = "Aram";
echo "<p>Hey</p>";        // HTML tags inside a string
echo $my_var . "Hey";     // joining a variable and a string
echo "<br>";
echo "$my_var";           // a variable inside double quotes
echo "<br>";
$var1 = "Hello";
$var2 = "";               // start with an empty string
$var2 .= $var1 . "World"; // .= adds to the end
echo $var2;
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

HTML tags can be used in strings.

HTML دەکرێت لە بەکاربهێنرێن.

Lineدێڕی 4

A variable and a string can be joined with the dot.

و دەکرێت بە خاڵ پێکەوە بلکێنرێن.

Lineدێڕی 6

A variable can be used inside a double-quoted string.

دەکرێت لەناو بەکاربهێنرێت.

Lineدێڕی 8-10

.= is another way of joining: it adds to the end of $var2. We give $var2 a starting value first.

.= ڕێگەیەکی ترە بۆ لکاندن: دەیخاتە کۆتایی $var2ـەوە. سەرەتا $var2 سەرەتایی پێ دەدەین.

Joining strings: the dot operatorپێکەوەلکاندن: کارپێکەری خاڵ

Adding to the end with .=خستنە سەر کۆتایی بە .=

$a .= $b; means the same as $a = $a . $b;. It adds $b to the end of $a and stores the result back in $a. The lecture calls it "another way of concatenation". It is the for strings.

$a .= $b; هەمان واتای $a = $a . $b;ـی هەیە. $b دەخاتە کۆتایی $aـەوە و ئەنجامەکە دیسان لە $aـدا هەڵدەگرێت. وانەکە پێی دەڵێت "ڕێگەیەکی تری ". ئەمە بۆ .

tiger.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$firstString = "The quick brown tiger";
$secondString = " jumped over the lazy cat";
?>
<?php
$thirdString = $firstString;
$thirdString .= $secondString;
echo $thirdString;
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

This string starts with a space. That space is what separates "tiger" and "jumped" later.

ئەم بە دەست پێ دەکات. هەر ئەو کە دواتر "tiger" و "jumped" لێک جیا دەکاتەوە.

Lineدێڕی 6

Copy the first string into a new variable.

یەکەم کۆپی بکە بۆ نوێ.

Lineدێڕی 7

Add the second string to its end.

دووەم بخە کۆتاییەکەیەوە.

Quick checkپشکنینی خێراAfter $s = "Hi"; $s .= " Aram"; $s .= "!";, what does $s hold?دوای $s = "Hi"; $s .= " Aram"; $s .= "!";، $s چی تێدایە؟

Joining strings: the dot operatorپێکەوەلکاندن: کارپێکەری خاڵ

Use the dot, not the plus signخاڵ بەکاربهێنە، نەک نیشانەی کۆ

In some languages + joins text. In PHP, + always means adding numbers. PHP tries to turn both sides into numbers, and text that is not a number stops the script with a . Also note 1 . 2: with spaces around the dot it joins 1 and 2; written as 1.2 it is a decimal number.

لە هەندێک زماندا + دەق پێکەوە دەلکێنێت. لە PHPـدا + هەمیشە واتای کۆکردنەوەی ژمارەیە. PHP هەوڵ دەدات هەردوو لا بکات بە ژمارە و دەقێک کە ژمارە نەبێت بە دەوەستێنێت. سەرنجی 1 . 2ـیش بدە: بە لە دەوری خاڵەکە 1 و 2 پێکەوە دەلکێنێت؛ بەڵام ئەگەر وەک 1.2 بنووسرێت ژمارەیەکی دەیدەییە.

plus.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "5" + "5";   // numbers: added
echo "<br>";
echo "5" . "5";   // strings: joined
echo "<br>";
echo 1 . 2;       // spaces around the dot make it the join operator
echo "<br>";
echo "Hello" + "World";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

"5" and "5" look like numbers, so + adds them: 10.

"5" و "5" لە ژمارە دەچن، بۆیە + کۆیان دەکاتەوە: ⁦10⁩.

Lineدێڕی 4

The dot joins them as text: 55.

خاڵ وەک دەق پێکەوەیان دەلکێنێت: ⁦55⁩.

Lineدێڕی 8

"Hello" is not a number, so PHP 8 throws a TypeError.

"Hello" ژمارە نییە، بۆیە ⁦PHP 8⁩ TypeError دەدات.

Quick checkپشکنینی خێراWhich line prints Hi Aram?کام دێڕ Hi Aram چاپ دەکات؟

Joining strings: the dot operatorپێکەوەلکاندن: کارپێکەری خاڵ

The echo table from the course notesخشتەکەی echo لە تێبینییەکانی کۆرسەکەدا

The course summary has an "Echo Table" with 15 small examples. We ran every row with PHP 8.5. The table assumes that $var1 holds "Var1Value", $var2 holds "Var2Value" and the func1() returns "Func1Value". One row is wrong in the notes; it is marked below. In the table, [tab] and [new line] stand for a real tab and a real new line character.

پوختەی کۆرسەکە بەشێکی بە ناوی "⁦Echo Table⁩" تێدایە کە ⁦15⁩ نموونەی بچووک لەخۆ دەگرێت. هەموو ڕیزەکانمان بە ⁦PHP 8.5⁩ تاقی کردەوە. ئەم خشتەیە وا دادەنێت کە $var1 "Var1Value" و $var2 "Var2Value" هەڵدەگرن و func1() دەقی "Func1Value" دەگەڕێنێتەوە. یەک ڕیز لە تێبینییەکاندا هەڵەیە؛ لە خوارەوە دیاری کراوە. لە خشتەکەدا [tab] و [new line] واتە تابی ڕاستەقینە و دێڕی نوێی ڕاستەقینە.

Echo table: every row checkedخشتەکەی Echo: هەموو ڕیزەکان پشکنراون
CodeکۆدThe notes sayتێبینییەکان دەڵێنReal output (PHP 8.5) ڕاستەقینە ⁦(PHP 8.5)⁩Commentتێبینی
echo $var1.$var2;Var1ValueVar2ValueVar1ValueVar2ValueCorrect. The dot adds no space.دروستە. خاڵ هیچ زیاد ناکات.
$var1 .= $var2; echo $var1;Var1Value Var2ValueVar1ValueVar2ValueWrong in the notes. .= adds no space either.لە تێبینییەکاندا هەڵەیە. .=ـیش هیچ زیاد ناکات.
echo $var1.func1();Var1ValueFunc1ValueVar1ValueFunc1ValueCorrect. The result of a can be joined too.دروستە. ئەنجامی دەکرێت بلکێنرێت.
echo $var1." ".$var2;Var1Value Var2ValueVar1Value Var2ValueCorrect. The space comes from " ". (The notes used curly quotes.)دروستە. لە " "ـەوە دێت. (تێبینییەکان گوتەی چەماوەیان بەکارهێنابوو.)
echo "$var1";Var1ValueVar1ValueCorrect. Double quotes replace the variable.دروستە. جووتەگوتە دەگۆڕێت.
echo '$var1';$var1$var1Correct. Single quotes print the name.دروستە. تاکەگوتە ناوەکە چاپ دەکات.
echo "<pre>Hello\tWorld</pre>";Hello [tab] WorldHello[tab]WorldCorrect. \t becomes a tab.دروستە. \t دەبێت بە تاب.
echo '<pre>Hello\tWorld</pre>';Hello\tWorldHello\tWorldCorrect. No escapes in single quotes.دروستە. لە تاکەگوتەدا نییە.
echo "I\'ll do it\nH";I\'ll do it HI\'ll do it[new line]HCorrect. The browser shows the new line as a space.دروستە. دێڕە نوێیەکە وەک پیشان دەدات.
echo 'I\'ll do it\nH';I'll do it\nHI'll do it\nHCorrect.دروستە.
$var = 4; print($var = 5);55Correct. An has the assigned value, and print prints it.دروستە. هەمان ئەو کە دادەنرێت و print چاپی دەکات.
echo true;11Correct. true prints as 1.دروستە. true وەک 1 چاپ دەبێت.
echo !false;11Correct. !false is true.دروستە. !false دەکاتە true.
echo false;[NOTHING](empty)Correct. false prints as an empty string.دروستە. false وەک بەتاڵ چاپ دەبێت.
echo null;[NOTHING](empty)Correct. null prints nothing.دروستە. null هیچ چاپ ناکات.

Rows 11 to 15 are about printing values rather than strings. You learn more about them in Output with echo and print and Data types.

ڕیزەکانی ⁦11⁩ تا ⁦15⁩ دەربارەی چاپکردنی ، نەک . زیاتر لەسەریان فێر دەبیت لە دەرخستە بە echo و print و جۆرەکانی دراوە.

Built-in string functionsکردارە ئامادەکانی زنجیرەنووسە

PHP comes with many ready-made for strings. You call a function by writing its name, then its in parentheses. The function gives back a result, called its . The original string does not change. To see the result, echo it or store it in a variable.

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

Definitionپێناسە

A function that comes with the language and is ready to use, such as len(), print() and max() in Python or strlen() and count() in PHP. Each language's manual explains them.

کە لەگەڵ زمانەکەدا دێت و ئامادەی بەکارهێنانە، وەک len()، print() و max() لە Pythonـدا یان strlen() و count() لە PHPـدا. ڕێبەری هەر زمانێک ڕوونیان دەکاتەوە.

Many examples below use the sentence from the lecture: $thirdString = "The quick brown tiger jumped over the lazy cat";

زۆرێک لە نموونەکانی خوارەوە ڕستەکەی وانەکە بەکاردەهێنن: $thirdString = "The quick brown tiger jumped over the lazy cat";

PHP Full Course for free 🐘Bro Code · Englishئینگلیزی · 3M viewsبینین · 65K likesلایک · Partبەشی 2:36:29–2:40:44 (ofلە 4:00:00)

How to create a function, send values in with arguments, and get a result back with return, with a short practice example.

چۆن دروست بکەیت، بە بنێریتە ناوی و بە return ئەنجامێک لێی وەربگریتەوە، لەگەڵ ڕاهێنانێکی کورت.

Plays 2:36:29–2:40:44: case, trim, replace, reverse, strlen, strpos. Stops before substr().

لە ⁦2:36:29⁩ تا ⁦2:40:44⁩ پەخش دەبێت: گەورە و بچووککردنی پیت، trim، گۆڕینەوە، پێچەوانەکردنەوە، strlen و strpos؛ پێش substr() ڕادەوەستێت.

Built-in string functionsکردارە ئامادەکانی زنجیرەنووسە

Counting characters: strlen()ژماردنی نووسەکان: strlen()

strlen(string) returns the length of a string: how many characters it has. Spaces and symbols count too. An empty string has length 0.

strlen(string) درێژیی دەگەڕێنێتەوە: چەند تێدایە. و هێماکانیش دەژمێردرێن. بەتاڵ درێژییەکەی 0ـە.

strlen.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo strlen("Hello world!");
echo "<br>";
$firstString = "The quick brown tiger";
echo strlen($firstString);
echo "<br>";
echo strlen("Str");
echo "<br>";
echo strlen("");
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

12 characters: 10 letters, 1 space and the !.

⁦12⁩ : ⁦10⁩ پیت، یەک و !.

Lineدێڕی 4-5

The lecture's sentence "The quick brown tiger" has 21 characters, including 3 spaces.

ڕستەکەی وانەکە "⁦The quick brown tiger" 21⁩ هەیە، لەوانە 3 .

Lineدێڕی 7

From the course notes: "Str" has 3 characters.

لە تێبینییەکانی کۆرسەکەوە: "Str" سێ هەیە.

Lineدێڕی 9

An empty string has length 0.

بەتاڵ درێژییەکەی 0ـە.

Built-in string functionsکردارە ئامادەکانی زنجیرەنووسە

Changing upper and lower caseگۆڕینی پیتی گەورە و بچووک

Four functions change the case of English letters. Each one returns a new string; the original variable does not change.

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

FunctionWhat it doesچی دەکات
strtolower($s)All letters small (lower case)هەموو پیتەکان بچووک دەکات
strtoupper($s)All letters capital (upper case)هەموو پیتەکان گەورە دەکات
ucfirst($s)Only the first character capitalتەنها یەکەم گەورە دەکات
ucwords($s)The first letter of every word capitalیەکەم پیتی هەموو وشەیەک گەورە دەکات

The lecture uses them in a page that mixes HTML text and small PHP blocks:

وانەکە لە لاپەڕەیەکدا بەکاریان دەهێنێت کە دەقی HTML و بلۆکی بچووکی PHP تێکەڵ دەکات:

case.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php $firstString = "The quick brown tiger"; ?>
<br />

Lower case:
<?php echo strtolower($firstString); ?><br />

Upper case:
<?php echo strtoupper($firstString); ?><br />

Uppercase first-letter:
<?php echo ucfirst($firstString); ?><br />

Uppercase words:
<?php echo ucwords($firstString); ?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

One short PHP block sets the variable.

بلۆکێکی کورتی PHP دادەنێت.

Lineدێڕی 4-5

Plain HTML text, then a PHP block that prints the result.

دەقی ئاسایی HTML، پاشان بلۆکێکی PHP کە ئەنجامەکە چاپ دەکات.

Lineدێڕی 11

ucfirst() shows no change here, because "The" already starts with a capital T.

ucfirst() لێرەدا هیچ گۆڕانێک پیشان نادات، چونکە "The" پێشتر بە T ـی گەورە دەست پێ دەکات.

Built-in string functionsکردارە ئامادەکانی زنجیرەنووسە

Removing spaces at the ends: trim()لابردنی بۆشایی لە سەر و کۆتایی: trim()

trim(string) removes from the beginning and the end of a string. It never touches the spaces in the middle. Whitespace means: space, tab (\t), new line (\n), carriage return (\r), the NUL byte (\0) and vertical tab (\x0B). ltrim() removes them only from the left (start), and rtrim() only from the right (end).

trim(string) لە سەرەتا و کۆتایی لادەبات. هەرگیز دەست لە ناوەڕاست نادات. مەبەست لە ئەمانەیە: ئاسایی، تاب (\t)، دێڕی نوێ (\n)، گەڕانەوە بۆ سەرەتای دێڕ (\r)، NUL (\0) و تابی شاقوڵی (\x0B). ltrim() تەنها لە لای چەپ (سەرەتا) لایان دەبات و rtrim() تەنها لە لای ڕاست (کۆتایی).

Definitionپێناسە

Characters you cannot see: spaces, tabs and new lines. Most languages ignore extra whitespace between parts of code, but whitespace inside a string is kept — and at the start of a line Python uses it as .

ئەو نووسانەی نابینرێن: بۆشایی، tab و دێڕی نوێ. زۆربەی زمانەکان گوێ بە بۆشایی زیادە لە نێوان بەشەکانی کۆددا نادەن، بەڵام بۆشایی لەناو دەمێنێتەوە؛ لە سەرەتای دێڕیشدا Python وەک بەکاری دەهێنێت.

The lecture joins $firstString with the trimmed $secondString. Look carefully at the result:

وانەکە $firstString لەگەڵ $secondStringـی trim کراو پێکەوە دەلکێنێت. بە وردی سەیری ئەنجامەکە بکە:

trim.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$firstString = "The quick brown tiger";
$secondString = " jumped over the lazy cat";
echo $fourthString = $firstString . trim($secondString);
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

$secondString starts with a space.

$secondString بە دەست پێ دەکات.

Lineدێڕی 4

trim() removes that leading space, so "tiger" and "jumped" are now stuck together.

trim() ئەو سەرەتا لادەبات، بۆیە ئێستا "tiger" و "jumped" بە یەکەوە نووساون.

Built-in string functionsکردارە ئامادەکانی زنجیرەنووسە

Seeing what trim() removesبینینی ئەوەی trim() لای دەبات

A browser hides extra spaces, so you cannot see what trim() did. Here the text is printed between square brackets inside <pre>, which keeps every space visible:

دەشارێتەوە، بۆیە ناتوانیت ببینیت trim() چی کردووە. لێرەدا دەقەکە لە نێوان دوو کەوانەی چوارگۆشەدا لەناو <pre>ـدا چاپ دەکرێت، کە هەموو دیار دەهێڵێتەوە:

trim-ends.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$name = "   Aram Ali   ";
echo "<pre>";
echo "[" . $name . "]\n";
echo "[" . trim($name) . "]\n";
echo "[" . ltrim($name) . "]\n";
echo "[" . rtrim($name) . "]\n";
echo "[" . trim("A     B") . "]\n";
echo "</pre>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

The original: 3 spaces on each side.

ڕەسەنەکە: 3 لە هەر لایەک.

Lineدێڕی 5

trim(): both ends cleaned.

trim(): هەردوو سەر پاک کراونەتەوە.

Lineدێڕی 6

ltrim(): only the left side.

ltrim(): تەنها لای چەپ.

Lineدێڕی 7

rtrim(): only the right side.

rtrim(): تەنها لای ڕاست.

Lineدێڕی 8

The 5 spaces in the middle stay.

5 ناوەڕاست دەمێننەوە.

Built-in string functionsکردارە ئامادەکانی زنجیرەنووسە

trim() never touches the middletrim() هەرگیز دەست لە ناوەڕاست نادات

The course notes say that trim("A B") gives A B. Let us check with var_dump(), which shows the exact string and its length:

تێبینییەکانی کۆرسەکە دەڵێن trim("A B") ئەنجامی A B دەدات. با بە var_dump() بیپشکنین، کە ڕێک و درێژییەکەی پیشان دەدات:

trim-check.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo trim("A     B");
echo "<pre>";
var_dump(trim("A     B"));
var_dump(trim("A \t B"));
var_dump(trim(" \t\n A B \r\0\x0B"));
echo "</pre>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

The browser shows A B, because it collapses the spaces. PHP still sends all 5 spaces.

A B پیشان دەدات، چونکە دەکاتە یەک. PHP هێشتا هەر 5 دەنێرێت.

Lineدێڕی 4

string(7): the result still has 7 characters, so the inner spaces are kept.

string(7): ئەنجامەکە هێشتا 7 هەیە، کەواتە ناوەوە ماون.

Lineدێڕی 5

The tab and spaces between A and B are kept too (5 characters).

تاب و نێوان A و B ـیش دەمێننەوە (⁦5⁩ ).

Lineدێڕی 6

Every kind of whitespace at the two ends is removed.

هەموو جۆرە لە دوو سەرەکەدا لادەبرێت.

Quick checkپشکنینی خێراWhat does trim(" a b ") return?trim(" a b ") چی دەگەڕێنێتەوە؟

Built-in string functionsکردارە ئامادەکانی زنجیرەنووسە

Replacing text: str_replace()گۆڕینی دەق: str_replace()

str_replace(search, replace, subject) finds every copy of search in subject and puts replace in its place. Remember the order of the three : what to find, what to put instead, and where to look. The search is : "world" and "WORLD" are different. str_ireplace() does the same job but ignores case.

str_replace(search, replace, subject) هەموو دانەیەکی search لەناو subjectـدا دەدۆزێتەوە و replace لە جێگەی دادەنێت. ڕیزبەندیی سێ لەبیر بێت: چی بدۆزرێتەوە، چی لە جێگەی دابنرێت و لە کوێدا بگەڕێین. گەڕانەکە : "world" و "WORLD" جیاوازن. str_ireplace() هەمان کار دەکات بەڵام گوێ نادات بە گەورە و بچووکیی پیت.

replace.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$thirdString = "The quick brown tiger jumped over the lazy cat";
echo str_replace("quick", "super-fast", $thirdString);
echo "<br>";
echo str_replace("Design", "Programming", "Web Design");
echo "<br>";
$a = "ADilanA";
echo str_replace("A", "B", $a);
echo "<br>";
echo str_replace("a", "o", "banana");
echo "<br>";
echo str_replace("WORLD", "Kurdistan", "Hello world");
echo "<br>";
echo str_ireplace("WORLD", "Kurdistan", "Hello world");
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

From the lecture: "quick" becomes "super-fast".

لە وانەکەوە: "quick" دەبێت بە "⁦super-fast⁩".

Lineدێڕی 5

From the slide deck: "Design" becomes "Programming".

لە سلایدەکانەوە: "Design" دەبێت بە "Programming".

Lineدێڕی 7-8

From the notes: both letters A are replaced, not only the first one.

لە تێبینییەکانەوە: هەردوو پیتی A دەگۆڕدرێن، نەک تەنها یەکەمیان.

Lineدێڕی 10

All three a letters become o.

هەر سێ پیتی a دەبن بە o.

Lineدێڕی 12

Nothing changes: "WORLD" (capitals) is not found in "Hello world".

هیچ ناگۆڕێت: "WORLD" (بە پیتی گەورە) لە "⁦Hello world⁩"ـدا نادۆزرێتەوە.

Lineدێڕی 14

str_ireplace() ignores case, so it finds "world".

str_ireplace() گوێ نادات بە گەورە و بچووکی، بۆیە "world" دەدۆزێتەوە.

Quick checkپشکنینی خێراWhat does str_replace("a", "e", "banana") return?str_replace("a", "e", "banana") چی دەگەڕێنێتەوە؟

Built-in string functionsکردارە ئامادەکانی زنجیرەنووسە

Repeating text: str_repeat()دووبارەکردنەوەی دەق: str_repeat()

str_repeat(string, times) returns the string repeated the given number of times, with nothing between the copies.

str_repeat(string, times) بە ئەو ژمارەیەی دیاری کراوە دووبارە دەکاتەوە و دەیگەڕێنێتەوە، بەبێ هیچ شتێک لە نێوان کۆپییەکاندا.

repeat.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$thirdString = "The quick brown tiger jumped over the lazy cat";
echo str_repeat("A", 2);
echo "<br>";
echo str_repeat("=", 20);
echo "<br>";
echo str_repeat($thirdString, 2);
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

From the notes: "A" twice is AA.

لە تێبینییەکانەوە: "A" دوو جار دەبێت بە AA.

Lineدێڕی 5

Useful for drawing a line of 20 = signs.

بەسوودە بۆ کێشانی هێڵێک لە ⁦20⁩ نیشانەی =.

Lineدێڕی 7

From the lecture: the whole sentence twice, stuck together.

لە وانەکەوە: هەموو دەقەکە دوو جار، بە یەکەوە نووساو.

Built-in string functionsکردارە ئامادەکانی زنجیرەنووسە

Reversing text: strrev()پێچەوانەکردنەوەی دەق: strrev()

strrev(string) returns the string backwards: the last character comes first.

strrev(string) بە پێچەوانەوە دەگەڕێنێتەوە: دوایین دەبێتە یەکەم.

reverse.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo strrev("Hello world!");
echo "<br>";
echo strrev("12345");
?>

Built-in string functionsکردارە ئامادەکانی زنجیرەنووسە

Finding a position: strpos()دۆزینەوەی شوێن: strpos()

strpos(haystack, needle) searches for the text needle inside the string haystack. It returns the position (the ) where the first match starts. Positions start at 0, not 1. If the text is not found, strpos() returns false. A third , the offset, tells PHP where to start searching; the returned position is still counted from the start of the string.

strpos(haystack, needle) بەدوای دەقی needleـدا لەناو haystackـدا دەگەڕێت. شوێنی () دەستپێکی یەکەم دۆزراوە دەگەڕێنێتەوە. ژمارەی شوێنەکان لە 0ـەوە دەست پێ دەکەن، نەک لە 1. ئەگەر دەقەکە نەدۆزرایەوە، strpos() false دەگەڕێنێتەوە. سێیەم ⁦(offset)⁩ بە PHP دەڵێت لە کوێوە دەست بە گەڕان بکات؛ بەڵام شوێنە گەڕاوەکە هەر لە سەرەتای دەژمێردرێت.

Definitionپێناسە

The number that gives an item's position in a list, array or string. Counting starts at 0, so the first item is items[0] ($items[0] in PHP); Python also allows that count from the end.

ئەو ژمارەیەیە کە شوێنی دانەیەک لە لیست، ڕیزەک یان زنجیرەنووسەیەکدا دیاری دەکات. ژماردن لە سفرەوە دەست پێ دەکات، بۆیە یەکەم دانە items[0]ـە (لە PHPـدا $items[0])؛ Python ڕێگە بە دەدات کە لە کۆتاییەوە دەژمێرن.

The string "Hello world!" drawn as 12 boxes, one character per box, numbered 0 to 11 underneath. strlen gives 12. The word world starts at index 6, so strpos gives 6, and substr($s, 6, 5) takes the 5 characters from index 6: world.دەقی "Hello world!" وەک 12 چوارگۆشە کێشراوە، هەر پیت یان هێمایەک لە چوارگۆشەیەکدا و لە ژێرەوە لە 0 تا 11 ژمارە کراون. strlen ئەنجامی 12 دەدات. وشەی world لە شوێنی 6ـەوە دەست پێ دەکات، بۆیە strpos ئەنجامی 6 دەدات و substr($s, 6, 5) پێنج پیت لە شوێنی 6ـەوە وەردەگرێت: world.
Every has an , starting from 0. strpos() returns an index; substr() uses one.هەر هەیە کە لە 0ـەوە دەست پێ دەکات. strpos() دەگەڕێنێتەوە؛ substr() بەکاردەهێنێت.CêIT
strpos.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$thirdString = "The quick brown tiger jumped over the lazy cat";
echo strpos("Hello world!", "world");
echo "<br>";
echo strpos($thirdString, "brown");
echo "<br>";
echo strpos("brown black", "b");
echo "<br>";
echo strpos("brown black", "b", 2);
echo "<br>";
var_dump(strpos("Hello world!", "xyz"));
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

From the slide deck: "world" starts at position 6 (H=0, e=1, l=2, l=3, o=4, space=5, w=6).

لە سلایدەکانەوە: "world" لە شوێنی 6ـەوە دەست پێ دەکات (⁦H=0⁩، ⁦e=1⁩، ⁦l=2⁩، ⁦l=3⁩، ⁦o=4⁩، =5، ⁦w=6⁩).

Lineدێڕی 5

From the lecture: "brown" starts at position 10.

لە وانەکەوە: "brown" لە شوێنی ⁦10⁩ـەوە دەست پێ دەکات.

Lineدێڕی 7

The first "b" is the very first character, position 0.

یەکەم "b" یەکەمین ، شوێنی 0.

Lineدێڕی 9

From the notes: with offset 2, PHP skips the first "b" and finds the one in "black" at position 6.

لە تێبینییەکانەوە: بە offsetی 2، PHP یەکەم "b" تێدەپەڕێنێت و ئەوەی ناو "black" لە شوێنی 6 دەدۆزێتەوە.

Lineدێڕی 11

Not found: the result is false, not a number. var_dump() shows this clearly.

نەدۆزرایەوە: ئەنجامەکە falseـە، نەک ژمارە. var_dump() ئەمە بە ڕوونی پیشان دەدات.

Built-in string functionsکردارە ئامادەکانی زنجیرەنووسە

The 0 versus false trapتەڵەی 0 بەرامبەر false

When the text is found at the very beginning, strpos() returns 0. In an if, PHP treats 0 like false. So if (strpos(...)) says "not found" exactly when the text is at the start! Always compare the result with !== false ("is not identical to false"). In PHP 8 you can also use str_contains(), which simply returns true or false.

کاتێک دەقەکە لە یەکەمین شوێندا دەدۆزرێتەوە، strpos() ژمارە 0 دەگەڕێنێتەوە. لەناو ifـدا PHP 0 وەک false دادەنێت. کەواتە if (strpos(...)) ڕێک کاتێک دەقەکە لە سەرەتادایە دەڵێت "نەدۆزرایەوە"! هەمیشە ئەنجامەکە بە !== false بەراورد بکە ("وەک false نییە"). لە ⁦PHP 8⁩ـدا دەتوانیت str_contains()ـیش بەکاربهێنیت کە تەنها true یان false دەگەڕێنێتەوە.

contains.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$text = "Hello world";

// WRONG: position 0 is treated like false
if (strpos($text, "Hello")) {
    echo "Found (wrong check)<br>";
} else {
    echo "Not found (wrong check)<br>";
}

// RIGHT: compare with !== false
if (strpos($text, "Hello") !== false) {
    echo "Found (right check)<br>";
} else {
    echo "Not found (right check)<br>";
}

// PHP 8: str_contains() gives a simple true or false
if (str_contains($text, "Hello")) {
    echo "Found (str_contains)";
}
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 5

strpos() returns 0 here. if (0) counts as false, so the wrong message is printed.

strpos() لێرەدا 0 دەگەڕێنێتەوە. if (0) وەک false دادەنرێت، بۆیە پەیامە نادروستەکە چاپ دەبێت.

Lineدێڕی 12

0 !== false is true, because 0 is a number and false is a boolean.

0 !== false ڕاستە، چونکە 0 ژمارەیە و false .

Lineدێڕی 19

str_contains() (PHP 8 and later) answers only yes or no.

str_contains() (⁦PHP 8⁩ و دواتر) تەنها بەڵێ یان نەخێر دەڵێت.

Quick checkپشکنینی خێراWhat does echo strpos("PHP is fun", "P"); print?echo strpos("PHP is fun", "P"); چی چاپ دەکات؟

Built-in string functionsکردارە ئامادەکانی زنجیرەنووسە

Getting the rest of a string: strstr() and strchr()وەرگرتنی باقیی زنجیرەنووسەیەک: strstr() و strchr()

strstr(haystack, needle) finds the first match of needle and returns the part of the string from that match to the end. It does not return a position. strchr() is another name (an alias) for the same function. If you pass true as the third , you get the part before the match instead. If nothing is found, the result is false.

strstr(haystack, needle) یەکەم دۆزراوەی needle دەدۆزێتەوە و ئەو بەشەی دەگەڕێنێتەوە کە لەو شوێنەوە تا کۆتایییە. شوێن ناگەڕێنێتەوە. strchr() ناوێکی ترە بۆ هەمان . ئەگەر true وەک سێیەم بنێریت، لە جیاتی ئەوە بەشی پێش دۆزراوەکە وەردەگریت. ئەگەر هیچ نەدۆزرایەوە، ئەنجامەکە falseـە.

strstr.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$thirdString = "The quick brown tiger jumped over the lazy cat";
echo strstr($thirdString, "brown");
echo "<br>";
echo strchr($thirdString, "z");
echo "<br>";
echo strstr("Hello Boys", "B");
echo "<br>";
echo strstr("Hello Boys", "o");
echo "<br>";
echo strstr("user@example.com", "@", true);
echo "<br>";
var_dump(strstr("Hello", "z"));
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

From the lecture ("Find"): everything from "brown" to the end.

لە وانەکەوە ⁦("Find")⁩: هەموو شتێک لە "brown"ـەوە تا کۆتایی.

Lineدێڕی 5

From the lecture ("Find character"): strchr() gives the rest from the first "z", not just one character.

لە وانەکەوە ⁦("Find character")⁩: strchr() باقییەکە لە یەکەم "z"ـەوە دەدات، نەک تەنها یەک .

Lineدێڕی 7

From the notes: the rest from "B".

لە تێبینییەکانەوە: باقییەکە لە "B"ـەوە.

Lineدێڕی 9

The first "o" is in "Hello", so the result is o Boys with a small o.

یەکەم "o" لەناو "Hello"دایە، بۆیە ئەنجامەکە o Boysـە بە o ـی بچووک.

Lineدێڕی 11

With true: the part before the "@".

لەگەڵ true: ئەو بەشەی پێش "@".

Lineدێڕی 13

Not found: false.

نەدۆزرایەوە: false.

Quick checkپشکنینی خێراWhat does strstr("2026-10-16", "-") return?strstr("2026-10-16", "-") چی دەگەڕێنێتەوە؟

Built-in string functionsکردارە ئامادەکانی زنجیرەنووسە

Cutting out a part: substr()بڕینی بەشێک: substr()

substr(string, start, length) returns part of a string. start is the index of the first character you want (counting from 0). length is how many characters to take. If you leave out length, you get everything to the end. A negative start counts from the end: -3 means "the last three characters".

substr(string, start, length) بەشێک لە دەگەڕێنێتەوە. start ئەو یەکەم کە دەتەوێت (لە 0ـەوە دەژمێردرێت). length دەڵێت چەند وەربگیرێت. ئەگەر length نەنووسیت، هەموو شتێک تا کۆتایی وەردەگریت. startـی سالب لە کۆتاییەوە دەژمێرێت: -3 واتە "سێ کۆتایی".

substr.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$thirdString = "The quick brown tiger jumped over the lazy cat";
echo substr($thirdString, 5, 10);
echo "<br>";
echo substr("Hello world", 6);
echo "<br>";
echo substr("ABCDEF", 2, 3);
echo "<br>";
echo substr("ABCDEF", 2, 2);
echo "<br>";
echo substr("Hello", -3);
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

From the lecture: start at index 5 (the "u" of "quick") and take 10 characters.

لە وانەکەوە: لە 5ـەوە (⁦"u⁩"ـی "⁦quick"⁩) دەست پێ بکە و ⁦10⁩ وەربگرە.

Lineدێڕی 5

From the slide deck: no length, so everything from index 6 to the end.

لە سلایدەکانەوە: درێژی نییە، بۆیە هەموو شتێک لە 6ـەوە تا کۆتایی.

Lineدێڕی 7-9

From the notes: A=0, B=1, C=2. Start at C and take 3 (CDE) or 2 (CD).

لە تێبینییەکانەوە: ⁦A=0⁩، ⁦B=1⁩، ⁦C=2⁩. لە C دەست پێ بکە و ⁦3 (CDE)⁩ یان ⁦2 (CD)⁩ وەربگرە.

Lineدێڕی 11

Negative start: the last 3 characters.

دەستپێکی سالب: 3 کۆتایی.

Quick checkپشکنینی خێراWhat does echo substr("Kurdistan", 0, 4); print?echo substr("Kurdistan", 0, 4); چی چاپ دەکات؟

Built-in string functionsکردارە ئامادەکانی زنجیرەنووسە

Splitting and joining: explode() and implode()لەتکردن و پێکەوەلکاندن: explode() و implode()

explode(separator, string) cuts a string into pieces wherever it finds the separator, and returns the pieces as an . implode(glue, array) does the opposite: it joins the of an array into one string, with the glue between them. join() is just another name for implode().

explode(separator, string) لە هەر شوێنێک جیاکەرەوەکەی تێدا بێت لەت دەکات و پارچەکان وەک دەگەڕێنێتەوە. implode(glue, array) پێچەوانەکەی دەکات: دەکاتە یەک و "glue" دەخاتە نێوانیانەوە. join() تەنها ناوێکی ترە بۆ implode().

A flow from left to right: the string "red,green,blue" goes through explode(",", $s) and becomes an array with three elements, red at index 0, green at index 1 and blue at index 2. The array then goes through implode(" - ", $a) and becomes the string "red - green - blue".ڕەوتێک لە چەپەوە بۆ ڕاست: دەقی "red,green,blue" بە explode(",", $s)ـدا تێدەپەڕێت و دەبێت بە سێ پارچەی ژمارەکراو: red لە شوێنی 0، green لە شوێنی 1 و blue لە شوێنی 2. پاشان ئەو سێ پارچەیە بە implode(" - ", $a)ـدا تێدەپەڕن و دەبنەوە بە دەقی "red - green - blue".
explode() turns a into an ; implode() turns an array back into a string.explode() دەکات بە ؛ implode() دەکاتەوە بە .CêIT
explode.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$str = "Web programming is easy to learn.";
print_r(explode(" ", $str));
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

Split at every space. Each word becomes one element; the full stop stays with "learn.".

لە هەر لەتی بکە. هەر وشەیەک دەبێت بە ؛ خاڵەکە لەگەڵ "learn." دەمێنێتەوە.

colors.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$colors = explode(",", "red,green,blue");
echo $colors[0];
echo "<br>";
echo $colors[1];
echo "<br>";
echo count($colors);
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

Split a comma-separated list.

لیستێک لەت بکە کە بە کۆما جیا کراونەتەوە.

Lineدێڕی 3-5

Each piece has an index, starting from 0.

هەر پارچەیەک هەیە کە لە 0ـەوە دەست پێ دەکات.

Lineدێڕی 7

count() tells how many pieces there are.

count() دەڵێت چەند پارچە هەیە.

join.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$input = array('Web', 'Programming', 'Simply', 'Easy', 'Learning');
echo join(" ", $input);
echo "<br>";
echo implode(" - ", $input);
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

An array of five words.

لە پێنج وشە.

Lineدێڕی 3

From the slide deck: join() with a space between the words.

لە سلایدەکانەوە: join() بە لە نێوان وشەکاندا.

Lineدێڕی 5

implode() gives the same kind of result; here the glue is " - ".

implode() هەمان جۆرە ئەنجام دەدات؛ لێرەدا glue بریتییە لە " - ".

Quick checkپشکنینی خێراWhat does implode("-", ["a", "b", "c"]) return?implode("-", ["a", "b", "c"]) چی دەگەڕێنێتەوە؟

Built-in string functionsکردارە ئامادەکانی زنجیرەنووسە

Fingerprints of text: md5()پەنجەمۆری دەق: md5()

md5(string) calculates the MD5 hash of a string. A turns any text into a short, fixed-length code, like a fingerprint. The same text always gives the same hash, and a tiny change (even one capital letter) gives a completely different hash. An MD5 hash is always 32 characters long. You cannot turn a hash back into the original text.

md5(string) هاشی ⁦MD5⁩ی هەژمار دەکات. هەر دەقێک دەکات بە کۆدێکی کورت بە درێژییەکی جێگیر، وەک پەنجەمۆر. هەمان دەق هەمیشە هەمان هاش دەدات و گۆڕانێکی زۆر بچووک (تەنانەت یەک پیتی گەورە) هاشێکی تەواو جیاواز دەدات. هاشی ⁦MD5⁩ هەمیشە ⁦32⁩ . ناتوانیت هاش بگەڕێنیتەوە بۆ دەقە ڕەسەنەکە.

Definitionپێناسە

A function that turns any input into a short value of fixed size, called a hash; the same input always gives the same hash. A uses a fast hash function to choose where each is stored. Security uses cryptographic hash functions such as SHA-256, whose hash cannot be turned back into the input; md5() and sha1() are too fast and weak for passwords.

هەر نێوخستەیەک دەگۆڕێت بۆ نرخێکی کورتی قەبارە جێگیر کە پێی دەوترێت هاش؛ هەمان نێوخستە هەمیشە هەمان هاش دەدات. کرداری هاشی خێرا بەکار دەهێنێت بۆ ئەوەی بڕیار بدات هەر لە کوێ هەڵبگیرێت. ئاسایش کرداری هاشی شفرەیی بەکار دەهێنێت، وەک ⁦SHA-256⁩، کە هاشەکەی ناگەڕێتەوە بۆ نێوخستەکە؛ md5() و sha1() بۆ تێپەڕەوشە زۆر خێرا و لاوازن.

md5.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$str = "Hello";
echo md5($str);
echo "<br>";
echo md5("hello");
echo "<br>";
echo strlen(md5("A much longer sentence gives a hash of the same length."));
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

From the slide deck: the MD5 hash of "Hello".

لە سلایدەکانەوە: هاشی ⁦MD5⁩ی "Hello".

Lineدێڕی 5

Only the first letter is different, but the hash is completely different.

تەنها یەکەم پیت جیاوازە، بەڵام هاشەکە تەواو جیاوازە.

Lineدێڕی 7

Any length of text gives a 32-character hash.

دەقی هەر درێژییەک بێت هاشێکی ⁦32⁩ نووسەیی دەدات.

Quick checkپشکنینی خێراA login page must store users' passwords. Which function should it use?لاپەڕەیەکی دەبێت هەڵبگرێت. کام بەکاربهێنێت؟

Built-in string functionsکردارە ئامادەکانی زنجیرەنووسە

Making text safe for HTML: htmlspecialchars()سەلامەتکردنی دەق بۆ HTML: htmlspecialchars()

htmlspecialchars(string) converts the special characters of HTML into and returns the converted string. An HTML entity is a short code such as &lt; that the browser shows as the character < but never treats as a tag. This way a visitor cannot inject their own tags or scripts into your page.

htmlspecialchars(string) HTML دەکات بە و دەگەڕێنێتەوە. کۆدێکی کورتە وەک &lt; کە وەک < پیشانی دەدات بەڵام هەرگیز وەک سەیری ناکات. بەم شێوەیە سەردانیکەر ناتوانێت یان خۆی بخاتە ناو لاپەڕەکەتەوە.

Definitionپێناسە

A short code that stands for a character in HTML, such as &lt; for < or &amp; for &. The browser shows the character but never treats it as part of a .

کۆدێکی کورتە کە لە HTMLـدا جێگەی نووسەیەک دەگرێتەوە، وەک &lt; بۆ < یان &amp; بۆ &. نووسەکە پیشان دەدات، بەڵام هەرگیز وەک بەشێک لە مامەڵەی لەگەڵ ناکات.

What htmlspecialchars() converts (PHP 8.1 and later)ئەوەی ⁦htmlspecialchars()⁩ دەیگۆڕێت (⁦PHP 8.1⁩ و دواتر)
CharacterBecomesدەبێت بە
&&amp;
"&quot;
'&#039;
<&lt;
>&gt;
safe.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$comment = "<b>Hi</b> & welcome";
echo $comment;
echo "<br>";
echo htmlspecialchars($comment);
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

Printed as it is: the browser makes "Hi" bold.

وەک خۆی چاپ دەکرێت: "Hi" تۆخ دەکات.

Lineدێڕی 5

Converted: the browser shows the tags as plain text.

گۆڕدراو: وەک دەقی ئاسایی پیشان دەدات.

Built-in string functionsکردارە ئامادەکانی زنجیرەنووسە

Why it matters: stopping XSSبۆچی گرنگە: ڕێگرتن لە XSS

htmlspecialchars() matters most for text that comes from users. Imagine a visitor types this "comment" into your form. Printed directly, it would run as JavaScript in every reader's browser. After htmlspecialchars() it is just harmless text:

htmlspecialchars() زیاتر بۆ ئەو دەقانە گرنگە کە لە دێن. وای دابنێ سەردانیکەرێک ئەم "لێدوانە" لە دەنووسێت. ئەگەر ڕاستەوخۆ چاپ بکرێت، وەک JavaScript لە هەموو خوێنەرێکدا کار دەکات. دوای htmlspecialchars() تەنها دەقێکی بێزیانە:

comment.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$comment = "<script>alert('Hacked!')</script>";
echo htmlspecialchars($comment);
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

The <script> tag is converted, so it cannot run.

<script> گۆڕدراوە، بۆیە ناتوانێت کار بکات.

quotes-safe.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo htmlspecialchars("Tom & \"Jerry\" say 'hi' <3");
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

All five special characters are converted: &, ", ', < and >.

هەر پێنج دەگۆڕدرێن: &، "، '، < و >.

Quick checkپشکنینی خێراWhat does htmlspecialchars("<b>") return?htmlspecialchars("<b>") چی دەگەڕێنێتەوە؟

Cracking Websites with Cross Site Scripting - ComputerphileComputerphile · Englishئینگلیزی · 1.6M viewsبینین · 40K likesلایک

Tom Scott shows how text with a script tag can attack a website, and why websites must make special characters safe before showing them.

تۆم سکۆت پیشان دەدات چۆن دەقێک کە <script> تێدایە دەتوانێت هێرش بکاتە سەر و بۆچی دەبێت پێش پیشاندان نیشانە تایبەتەکان بێمەترسی بکەن.

Whole video: what XSS is and why output must be escaped.

هەموو ڤیدیۆکە: چییە و بۆچی دەبێت پێش پیشاندان بێمەترسی بکرێت (escape).

Built-in string functionsکردارە ئامادەکانی زنجیرەنووسە

Summary table of string functionsپوختەی کردارەکانی زنجیرەنووسە لە خشتەیەکدا

The slide deck calls these "ten functions you will use constantly". Strictly, concatenation is an operator, so the deck lists nine functions and one operator. This table adds the other functions from the lecture and the notes. Every example result was checked with PHP 8.5. Try each one once!

سلایدەکان ئەمانە ناو دەنێن "دە کە هەمیشە بەکاریان دەهێنیت". لە ڕاستیدا ، بۆیە سلایدەکان نۆ و یەک دەژمێرن. ئەم خشتەیە تری وانەکە و تێبینییەکانیشی تێدایە. ئەنجامی هەموو نموونەیەک بە ⁦PHP 8.5⁩ پشکنراوە. هەر یەکێکیان یەک جار تاقی بکەرەوە!

String functions at a glance بە کورتی
FunctionWhat it doesچی دەکاتExampleنموونەResultئەنجام
Concatenation . .Joins strings (an , not a function) پێکەوە دەلکێنێت (، نەک )"Web" . " " . "PHP"Web PHP
strlen()strlen()Length of a stringدرێژیی strlen("Hello world!")12
strtolower()strtolower()All letters smallهەموو پیتەکان بچووکstrtolower("Str")str
strtoupper()strtoupper()All letters capitalهەموو پیتەکان گەورەstrtoupper("Str")STR
ucfirst()ucfirst()First character capitalیەکەم گەورەucfirst("str")Str
ucwords()ucwords()First letter of each word capitalیەکەم پیتی هەر وشەیەک گەورەucwords("str str")Str Str
trim()trim()Removes whitespace from both ends only تەنها لە هەردوو سەر لادەباتtrim(" Hi ")Hi
str_replace()str_replace()Replaces every matchهەموو دۆزراوەیەک دەگۆڕێتstr_replace("A", "B", "ADilanA")BDilanB
str_repeat()str_repeat()Repeats a string دووبارە دەکاتەوەstr_repeat("A", 2)AA
strrev()strrev()Reverses a string پێچەوانە دەکاتەوەstrrev("Hello world!")!dlrow olleH
strpos()strpos()Position of the first match, or falseشوێنی یەکەم دۆزراوە، یان falsestrpos("Hello world!", "world")6
strstr() / strchr()strstr() / strchr()The rest of the string from the first matchباقیی لە یەکەم دۆزراوەوەstrstr("Hello Boys", "B")Boys
substr()substr()Part of a string: start, lengthبەشێک لە : دەستپێک، درێژیsubstr("ABCDEF", 2, 3)CDE
explode()explode()Splits a string into an array لەت دەکات بۆ explode(",", "a,b")["a", "b"]
implode() / join()implode() / join()Joins array elements into a string دەکاتە join(" ", ["Web", "PHP"])Web PHP
md5()md5()32-character MD5 hash (not for passwords)هاشی ⁦MD5⁩ی ⁦32⁩ نووسەیی (نەک بۆ )md5("Hello")8b1a9953c4611296a827abf8c47804d7
htmlspecialchars()htmlspecialchars()Converts < > & " ' to HTML entities< > & " ' دەکات بە htmlspecialchars("<b>")&lt;b&gt;

Built-in string functionsکردارە ئامادەکانی زنجیرەنووسە

Checking the course notes' string tableپشکنینی خشتەکەی زنجیرەنووسەکانی تێبینییەکانی کۆرسەکە

The course notes ("Chp2 notes") and the course summary contain a table of string functions with their outputs. We ran every row with PHP 8.5, using straight quotes. Three outputs in the notes are wrong; they are marked below.

تێبینییەکانی کۆرسەکە ⁦("Chp2 notes")⁩ و پوختەی کۆرسەکە و لە شێوەی خشتەدا تێدایە. هەموو ڕیزێکمان بە ⁦PHP 8.5⁩ و بە نیشانەی گوتەی ڕاست تاقی کردەوە. سێ لە تێبینییەکاندا هەڵەن؛ لە خوارەوە دیاری کراون.

The notes' string table, every row checkedخشتەکەی تێبینییەکان: هەموو ڕیزەکان پشکنراون
Code (as in the notes, straight quotes)کۆد (وەک تێبینییەکان، بە گوتەی ڕاست)The notes sayتێبینییەکان دەڵێنReal output (PHP 8.5) ڕاستەقینە ⁦(PHP 8.5)⁩Verdictبڕیار
echo strToLower("Str");strstrCorrectدروستە
echo strToUpper("Str");STRSTRCorrectدروستە
$a = "ADilanA"; echo str_Replace("A", "B", $a);BDilanBBDilanBCorrect: every A is replacedدروستە: هەموو Aـیەک دەگۆڕدرێت
echo str_Repeat("A", 2);AAAACorrectدروستە
echo strSTR("Hello Boys", "B");BoysBoysCorrectدروستە
echo strSTR("Hello Boys", "o");O Boyso BoysWrong in the summary: the first o is the small o of "Hello"لە پوختەکەدا هەڵەیە: یەکەم o پیتی o ـی بچووکی ناو "Hello"ـە
echo subSTR("ABCDEF", 2, 3);CDECDECorrect: start at index 2, take 3دروستە: لە 2ـەوە دەست پێ بکە، 3 وەربگرە
echo subSTR("ABCDEF", 2, 2);CDCDCorrectدروستە
echo strPOS("brown black", "b", 2);66Correct: the offset 2 skips the first bدروستە: offsetی 2 یەکەم b تێدەپەڕێنێت
echo strChr("Hello", "He");HelloHelloCorrectدروستە
echo strChr("Hello", "e");elloelloCorrectدروستە
[BOOLEAN](no output given)strchr("Hello", "e", true) → HThe third, boolean argument true returns the part before the match سێیەم کە ، واتە true، ئەو بەشەی پێش دۆزراوەکە دەگەڕێنێتەوە
echo strLen("Str");33Correctدروستە
echo ucWords("str str");Str StrStr StrCorrectدروستە
echo ucFirst("str");StrStrCorrectدروستە
echo trim("A B");A BA BWrong: inner spaces stay; only the browser hides themهەڵەیە: ناوەوە دەمێننەوە؛ تەنها دەیانشارێتەوە
echo trim("A \t B");A BA [tab] BWrong: the tab and spaces in the middle stayهەڵەیە: تاب و ناوەڕاست دەمێننەوە

Common mistakesئەو هەڵانەی زۆر دەکرێن

  1. Curly quotes. Code copied from slides or a word processor often has “ ” or ‘ ’. PHP stops with a . Retype them as straight quotes.
  2. A missing $. trim(secondString) makes PHP look for a constant and stop with an Error. Write trim($secondString).
  3. Expecting the dot or .= to add a space. They never do. Add " " yourself.
  4. Joining with +. + adds numbers; "Hello" + "World" is a TypeError. Use the dot.
  5. Variables in single quotes. 'Hello $name' prints $name. Use double quotes or the dot.
  6. Calling a function without using the result. strtoupper($s); alone prints nothing. Use echo or store the result.
  7. Thinking trim() cleans the middle. It only removes whitespace at the two ends.
  8. Testing strpos() with a plain if. A match at position 0 looks like "not found". Use !== false or str_contains().
  9. Counting from 1. String positions start at 0: in "ABCDEF", C is at index 2.
  10. Using md5() for passwords. Use password_hash() and password_verify() instead.
  11. Printing user input without htmlspecialchars(). This opens the door to attacks.
  12. Using a variable that was never set. PHP shows Warning: Undefined variable. Give every variable a value first.
  13. Using strlen(), strrev() or strtoupper() on Kurdish text. They work on bytes and English letters only. Use the mb_ functions, such as mb_strlen().
  1. نیشانەی گوتەی چەماوە. ئەو کۆدەی لە سلاید یان نەرمەکاڵای نووسینەوە کۆپی دەکرێت زۆرجار “ ” یان ‘ ’ـی تێدایە. PHP بە دەوەستێت. بە نیشانەی گوتەی ڕاست بیاننووسەرەوە.
  2. $ـی ونبوو. trim(secondString) وا دەکات PHP بەدوای بگەڕێت و بە Error بوەستێت. بنووسە trim($secondString).
  3. چاوەڕوانی ئەوە کە خاڵ یان .= زیاد بکات. هەرگیز ناکەن. خۆت " " زیاد بکە.
  4. لکاندن بە +. + ژمارە کۆ دەکاتەوە؛ "Hello" + "World" TypeError دەدات. خاڵ بەکاربهێنە.
  5. لەناو تاکەگوتەدا. 'Hello $name' ناوی $name چاپ دەکات. جووتەگوتە یان خاڵ بەکاربهێنە.
  6. بانگکردنی بەبێ بەکارهێنانی ئەنجامەکەی. strtoupper($s); بە تەنها هیچ چاپ ناکات. echo بەکاربهێنە یان ئەنجامەکە هەڵبگرە.
  7. وا بیرکردنەوە کە trim() ناوەڕاست پاک دەکاتەوە. تەنها لە دوو سەرەکە لادەبات.
  8. پشکنینی strpos() بە ifـی سادە. دۆزراوەیەک لە شوێنی 0 وەک "نەدۆزرایەوە" دەردەکەوێت. !== false یان str_contains() بەکاربهێنە.
  9. ژماردن لە 1ـەوە. شوێنەکانی لە 0ـەوە دەست پێ دەکەن: لە "ABCDEF"ـدا C لە 2دایە.
  10. بەکارهێنانی md5() بۆ . لە جیاتی ئەوە password_hash() و password_verify() بەکاربهێنە.
  11. چاپکردنی بەبێ htmlspecialchars(). ئەمە دەرگا بۆ هێرشی دەکاتەوە.
  12. بەکارهێنانی کە هەرگیز پێ نەدراوە. PHP پەیامی Warning: Undefined variable پیشان دەدات. سەرەتا بە هەموو بدە.
  13. بەکارهێنانی strlen()، strrev() یان strtoupper() لەسەر دەقی کوردی. ئەمانە تەنها لەسەر و پیتی ئینگلیزی کار دەکەن. mb_ بەکاربهێنە، وەک mb_strlen().

Exercises and lab tasksڕاهێنان و ئەرکەکانی تاقیگە

Type every example yourself in your editor and run it with XAMPP. Predict the output before you run it, then compare.

هەموو نموونەیەک خۆت لە دەستکاریکەرەکەتدا بنووسە و بە XAMPP کاری پێ بکە. پێش ئەوەی کاری پێ بکەیت پێشبینی بکە، پاشان بەراوردی بکە.

ExerciseڕاهێنانLab 2, Example 4: single and double quotesتاقیگەی 2، نموونەی 4: تاکەگوتە و جووتەگوتە

Type and run Lab 2 Example 4 (shown in Escape sequences). Explain why the second line prints $my_str and why only the second <pre> line has a tab. Then change the second echo so that it also prints Hello, World!, but keep the single quotes.

نموونەی 4ی تاقیگەی 2 (کە لە هێما تایبەتەکان پیشان دراوە) بنووسە و کاری پێ بکە. ڕوونی بکەرەوە بۆچی دێڕی دووەم $my_str چاپ دەکات و بۆچی تەنها دێڕی دووەمی <pre> تابی تێدایە. پاشان echoـی دووەم بگۆڕە بۆ ئەوەی ئەویش Hello, World! چاپ بکات، بەڵام تاکەگوتەکان بهێڵەرەوە.

Hintئاماژە

Close the single-quoted string before the variable and join the pieces with the dot.

پێش دابخە و پارچەکان بە خاڵ پێکەوە بلکێنە.

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

Single quotes do not replace variables and do not understand \t, so line 2 prints the name $my_str and the first <pre> shows \t as two characters. Double quotes replace $my_str with World and turn \t into a real tab. \' puts a single quote inside a single-quoted string.

تاکەگوتە ناگۆڕێت و \t ناناسێتەوە، بۆیە دێڕی 2 ناوی $my_str چاپ دەکات و یەکەم <pre>، \t وەک دوو پیشان دەدات. جووتەگوتە $my_str بە World دەگۆڕێت و \t دەکات بە تابی ڕاستەقینە. \' تاکەگوتەیەک دەخاتە ناو .

quotes2.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$my_str = 'World';
echo 'Hello, ' . $my_str . '!<br>';
?>
ExerciseڕاهێنانLab 2, Example 9: concatenating stringsتاقیگەی 2، نموونەی 9: پێکەوەلکاندنی زنجیرەنووسەکان

Predict what this program prints, then run it. Where does the space between "Hello" and "World!" come from?

پێشبینی بکە ئەم چی چاپ دەکات، پاشان کاری پێ بکە. ئەو نێوان "Hello" و "⁦World!⁩" لە کوێوە دێت؟

concat.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$x = "Hello";
$y = " World!";
echo $x . $y; // Outputs: Hello World!
echo "<br>";

$x .= $y;
echo $x; // Outputs: Hello World!
?>
Show answerوەڵامەکە پیشان بدە
concat.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$x = "Hello";
$y = " World!";
echo $x . $y; // Outputs: Hello World!
echo "<br>";

$x .= $y;
echo $x; // Outputs: Hello World!
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

$x . $y joins the two strings without changing $x.

$x . $y دوو پێکەوە دەلکێنێت بەبێ گۆڕینی $x.

Lineدێڕی 7

$x .= $y changes $x itself; then it is printed.

$x .= $y خودی $x دەگۆڕێت؛ پاشان چاپ دەکرێت.

Both lines print Hello World!, as the comments in the lab say. The space is the first character of $y (" World!"); the dot adds nothing.

هەردوو دێڕ Hello World! چاپ دەکەن، وەک تاقیگەکە دەڵێن. یەکەم $yـە (" World!")؛ خاڵ هیچ زیاد ناکات.

ExerciseڕاهێنانLab 2, Examples 10 and 11: changing case and countingتاقیگەی 2، نموونەکانی ⁦10⁩ و ⁦11⁩: گۆڕینی قەبارەی پیت و ژماردن

Lab 2 converts the text "web programming " to upper case, to lower case, with only the first letter capital, with every word capital, and counts its length. Write one program that prints all five results, each on its own line. How long is the string, and why?

تاقیگەی 2 دەقی "web programming " دەکات بە پیتی گەورە، بە پیتی بچووک، تەنها یەکەم پیت گەورە، هەموو وشەیەک بە پیتی گەورە دەست پێ بکات و درێژییەکەی دەژمێرێت. بنووسە کە هەر پێنج ئەنجامەکە چاپ بکات، هەر یەکەیان لەسەر دێڕی خۆی. چەند درێژە و بۆچی؟

Hintئاماژە

strtoupper(), strtolower(), ucfirst(), ucwords(), strlen().

strtoupper()، strtolower()، ucfirst()، ucwords()، strlen().

Show answerوەڵامەکە پیشان بدە
case.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$var = "web programming ";
echo strtoupper($var);
echo "<br>";
echo strtolower($var);
echo "<br>";
echo ucfirst($var);
echo "<br>";
echo ucwords($var);
echo "<br>";
echo strlen($var);
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

The string ends with a space; the space is kept in every result.

بە کۆتایی دێت؛ ئەو لە هەموو ئەنجامێکدا دەمێنێتەوە.

Lineدێڕی 11

16 characters: 15 for "web programming" plus the trailing space.

⁦16⁩ : ⁦15⁩ بۆ "⁦web programming⁩" و یەک بۆ کۆتایی.

ExerciseڕاهێنانTry each string function onceهەر کردارێکی زنجیرەنووسە یەک جار تاقی بکەرەوە

The slide deck says: try each function once. Start with echo strlen("Hello world!"); (it prints 12). Then, using $s = "Hello world!";, print: its reverse, the position of "o", the text from position 6, the text in capitals, and the text with "world" replaced by "Kurdistan".

سلایدەکان دەڵێن: هەر یەک جار تاقی بکەرەوە. بە echo strlen("Hello world!"); دەست پێ بکە (⁦12⁩ چاپ دەکات). پاشان بە بەکارهێنانی $s = "Hello world!"; ئەمانە چاپ بکە: پێچەوانەکەی، شوێنی "o"، دەقەکە لە شوێنی 6ـەوە، دەقەکە بە پیتی گەورە و دەقەکە دوای گۆڕینی "world" بە "Kurdistan".

Show answerوەڵامەکە پیشان بدە
try.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo strlen("Hello world!");
echo "<br>";
$s = "Hello world!";
echo strrev($s);
echo "<br>";
echo strpos($s, "o");
echo "<br>";
echo substr($s, 6);
echo "<br>";
echo strtoupper($s);
echo "<br>";
echo str_replace("world", "Kurdistan", $s);
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 7

The first o is in "Hello", at position 4.

یەکەم o لەناو "Hello"دایە، لە شوێنی 4.

Lineدێڕی 9

No length: from position 6 to the end.

بێ درێژی: لە شوێنی 6ـەوە تا کۆتایی.

Exercises and lab tasksڕاهێنان و ئەرکەکانی تاقیگە

More practiceڕاهێنانی زیاتر

ExerciseڕاهێنانClean up a nameچاککردنی شێوەی ناوێک

A user typed their name as " aRAM aLI ". Write code that removes the extra spaces at the ends and prints the name as Aram Ali.

ناوەکەی بەم شێوەیە نووسیوە: " aRAM aLI ". کۆدێک بنووسە کە هەردوو سەر لاببات و ناوەکە وەک Aram Ali چاپ بکات.

Hintئاماژە

First make every letter small, then make the first letter of each word capital.

سەرەتا هەموو پیتەکان بچووک بکە، پاشان یەکەم پیتی هەر وشەیەک گەورە بکە.

Show answerوەڵامەکە پیشان بدە
name.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$name = "   aRAM aLI   ";
$clean = ucwords(strtolower(trim($name)));
echo $clean;
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

Functions can be nested: the innermost call runs first.

دەکرێت لەناو یەکتردا بن: ناوەوەترین بانگکردن یەکەم جار کار دەکات.

ExerciseڕاهێنانCheck an email addressپشکنینی ناونیشانی ئیمەیڵ

Given $email = "hana@example.com";, print Looks like an email if it contains @, otherwise Not an email. Then print the user name (the part before @) and the domain (the part after @).

بە پێی $email = "hana@example.com";، ئەگەر @ـی تێدا بوو Looks like an email چاپ بکە، ئەگەر نا Not an email. پاشان (بەشی پێش @) و (بەشی دوای @) چاپ بکە.

Hintئاماژە

Use strpos() with !== false, strstr() with true, and substr() with the position of @ plus 1.

strpos() لەگەڵ !== false، strstr() لەگەڵ true و substr() لەگەڵ شوێنی @ کۆ 1 بەکاربهێنە.

Show answerوەڵامەکە پیشان بدە
email.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$email = "hana@example.com";

if (strpos($email, "@") !== false) {
    echo "Looks like an email<br>";
} else {
    echo "Not an email<br>";
}

$at = strpos($email, "@");
echo "User: " . strstr($email, "@", true) . "<br>";
echo "Domain: " . substr($email, $at + 1);
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

Compare with !== false, so a match at position 0 still counts.

بە !== false بەراورد بکە، بۆ ئەوەی دۆزراوەیەک لە شوێنی 0ـیش هەژمار بکرێت.

Lineدێڕی 10-12

@ is at position 4, so the domain starts at position 5.

@ لە شوێنی 4دایە، بۆیە لە شوێنی 5ـەوە دەست پێ دەکات.

Summary and reviewپوختە و پێداچوونەوە

  • A is text in quotes. Single quotes print text exactly; double quotes replace variables and understand escape sequences.
  • A heredoc (<<<TEXT) is a long string that works like double quotes; a nowdoc (<<<'TEXT') works like single quotes.
  • The dot . joins strings, and .= adds to the end of a variable. Neither adds spaces.
  • String positions (indexes) start at 0. strpos() returns a position or false; check it with !== false.
  • trim() cleans only the two ends. str_replace() replaces every match. substr() cuts by start and length.
  • explode() turns a string into an array; implode()/join() turns an array into a string.
  • md5() makes a hash, but never use it for passwords. htmlspecialchars() makes text safe to print in HTML.
  • دەقە لەناو نیشانەی گوتەدا. تاکەگوتە دەق وەک خۆی چاپ دەکات؛ جووتەگوتە دەگۆڕێت و دەناسێتەوە.
  • (<<<TEXT) درێژە کە وەک جووتەگوتە کار دەکات؛ nowdoc (<<<'TEXT') وەک تاکەگوتە کار دەکات.
  • خاڵ . پێکەوە دەلکێنێت و .= دەیخاتە کۆتایی . هیچیان زیاد ناکەن.
  • شوێنەکانی () لە 0ـەوە دەست پێ دەکەن. strpos() شوێنێک یان false دەگەڕێنێتەوە؛ بە !== false بیپشکنە.
  • trim() تەنها دوو سەرەکە پاک دەکاتەوە. str_replace() هەموو دۆزراوەیەک دەگۆڕێت. substr() بە دەستپێک و درێژی دەبڕێت.
  • explode() دەکات بە ؛ implode()/join() دەکات بە .
  • md5() هاش دروست دەکات، بەڵام هەرگیز بۆ بەکاری مەهێنە. htmlspecialchars() دەق سەلامەت دەکات بۆ چاپکردن لە HTMLـدا.
Review questionsپرسیارەکانی پێداچوونەوە
Why does echo 'Total: $sum'; print $sum instead of the number?بۆچی echo 'Total: $sum'; لە جیاتی ژمارەکە $sum چاپ دەکات؟

Because single quotes print text exactly as written. Use double quotes ("Total: $sum") or the dot ('Total: ' . $sum).

چونکە تاکەگوتە دەق ڕێک وەک خۆی چاپ دەکات. جووتەگوتە ("Total: $sum") یان خاڵ ('Total: ' . $sum) بەکاربهێنە.

What is the difference between \n and <br>?جیاوازیی نێوان \n و <br> چییە؟

\n (in double quotes) is a new line in the HTML source; the browser shows it as a space. <br> is an HTML tag that breaks the line on the page.

\n (لەناو جووتەگوتەدا) دێڕێکی نوێیە لە کۆدی HTML ـی نێردراودا؛ وەک پیشانی دەدات. <br> HTMLـە کە دێڕ لەسەر لاپەڕەکە دەشکێنێت.

What does $a .= "!"; do?$a .= "!"; چی دەکات؟

It adds ! to the end of $a. It is the same as $a = $a . "!";.

! دەخاتە کۆتایی $aـەوە. هەمان $a = $a . "!";ـە.

Why is if (strpos($text, "Hi")) dangerous?بۆچی if (strpos($text, "Hi")) مەترسیدارە؟

If $text starts with "Hi", strpos() returns 0, which if treats as false. Use strpos($text, "Hi") !== false.

ئەگەر $text بە "Hi" دەست پێ بکات، strpos() ژمارە 0 دەگەڕێنێتەوە، کە if وەک false دایدەنێت. strpos($text, "Hi") !== false بەکاربهێنە.

What do strstr("Hello Boys", "o") and strstr("Hello Boys", "o", true) return?strstr("Hello Boys", "o") و strstr("Hello Boys", "o", true) چی دەگەڕێننەوە؟

o Boys (from the first o to the end) and Hell (the part before the first o).

o Boys (لە یەکەم oـەوە تا کۆتایی) و Hell (بەشی پێش یەکەم o).

What does substr("Hello world", 6) return, and why?substr("Hello world", 6) چی دەگەڕێنێتەوە و بۆچی؟

world. Index 6 is the w (counting from 0), and with no length you get everything to the end.

world. 6 پیتی wـە (لە 0ـەوە دەژمێردرێت) و بەبێ درێژی هەموو شتێک تا کۆتایی وەردەگریت.

Why must you not store passwords with md5()?بۆچی نابێت تێپەڕەوشە بە md5() هەڵبگریت؟

MD5 is very fast, so attackers can guess billions of passwords per second, and identical passwords give identical hashes. Use password_hash() and password_verify().

⁦MD5⁩ زۆر خێرایە، بۆیە هێرشبەران دەتوانن لە هەر چرکەیەکدا ملیاران تاقی بکەنەوە و وەک یەک هاشی وەک یەک دەدەن. password_hash() و password_verify() بەکاربهێنە.

When should you use htmlspecialchars()?کەی دەبێت htmlspecialchars() بەکاربهێنیت؟

Every time you print text that came from a user (a form, a URL, a database), so that tags and scripts are shown as text instead of running.

هەر جارێک دەقێک چاپ دەکەیت کە لە هاتووە (، URL، )، بۆ ئەوەی و وەک دەق پیشان بدرێن لە جیاتی ئەوەی کار بکەن.

Is strToUpper() the same function as strtoupper()?ئایا strToUpper() و strtoupper() هەمان کردارن؟

Yes. PHP function names are not case-sensitive, but variable names are. Write function names in lower case.

بەڵێ. ناوی PHP نین، بەڵام ناوی . ناوی بە پیتی بچووک بنووسە.

Videoڤیدیۆ

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

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

PHP for beginners [ Kurdish ] - 2 - پی ئێچ پی بۆ ئاستی سەرەتاییK97 Media · Kurdish (Sorani)کوردی (سۆرانی) · 8K viewsبینین · 215 likesلایک

A lesson in Kurdish (Sorani): what a string is, why we use strings, and what PHP can do with them.

وانەیەک بە کوردیی سۆرانی: چییە، بۆچی بەکاری دەهێنین و چی دەتوانێت لەگەڵیدا بکات.

Kurdish (Sorani) overview of strings in PHP.

ناساندنێکی گشتی بە کوردیی سۆرانی بۆ .

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

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

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

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

Operatorsکارپێکەرەکان

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

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