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 و زیاتر). هەموو نموونەیەکی کۆرسەکە تاقی کراوەتەوە و ڕاست کراوەتەوە.
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,\tand\"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, andmd5()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 ئامرازی زۆری هەیە بۆ کارکردن لەگەڵ .
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"، ئەویش هەر زنجیرەنووسەیە.
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ـەوە دەست پێ دەکات.
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 نیشانەی گوتەی ڕاستی پێویستە (' یان "). نیشانەی گوتەی چەماوە (“ ” ‘ ’)، کە نەرمەکاڵاکانی نووسین خۆکارانە دایدەنێن، دروست دەکەن.
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 /> دێڕێکی نوێ لەسەر لاپەڕەکە دەست پێ دەکات.
<?php
echo "Hello World <br />";
echo 'Hello World <br />';
$my_variable = "Hello World";
echo $my_variable;
echo $my_variable . " Again";
?>Hello World Hello World Hello WorldHello World Again
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
Hello World <br />Hello World <br />Hello WorldHello World AgainExplain 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 /> چاپ بکە:
<?php
echo "Hello World <br />";
echo 'Hello World <br />';
$my_variable = "Hello World";
echo $my_variable . "<br />";
echo $my_variable . " Again";
?>Hello World Hello World Hello World Hello World Again
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
Hello World <br />Hello World <br />Hello World<br />Hello World AgainWriting stringsنووسینی زنجیرەنووسەکان
Single quotes or double quotes?تاکەگوتە یان جووتەگوتە؟
<?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!
?>My $variable will not print! My name will print!
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
My $variable will not print!<br>My name will print!Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3
Single quotes:
$variablestays as plain text.تاکەگوتە:
$variableوەک دەقێکی ئاسایی دەمێنێتەوە.- Lineدێڕی 6
Added so the two results appear on separate lines.
زیاد کراوە بۆ ئەوەی دوو ئەنجامەکە لەسەر دوو دێڕی جیا دەربکەون.
- Lineدێڕی 7
Double quotes: PHP puts the value
namein 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).
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". ئەم کارە ناکەن.
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 ... ?>ـی هەمان بێت. لێرەدا لە بلۆکی یەکەمدا دانراوە و لە بلۆکی دووەمدا لەناو جووتەگوتەدا چاپ دەکرێت:
<?php
$my_variable = "Hello World";
?>
<?php
echo "$my_variable Again.";
?>Hello World Again.
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
Hello World 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 لە هەردوو جۆری گوتەدا کار دەکەن. تەنها جیاوازە:
<?php
$friend = "Shilan";
$j = "<b>Bold</b> $friend";
$i = '<b>Bold</b> $friend';
echo $j;
echo "<br>";
echo $i;
?>Bold Shilan Bold $friend
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<b>Bold</b> Shilan<br><b>Bold</b> $friendExplain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3
Double quotes:
$friendbecomesShilan.جووتەگوتە:
$friendدەبێت بەShilan.- Lineدێڕی 4
Single quotes:
$friendstays as it is. The<b>tag still makes the word bold.تاکەگوتە:
$friendوەک خۆی دەمێنێتەوە.<b>هێشتا وشەکە تۆخ دەکات.- Lineدێڕی 6
Added: without it the two results would run together.
زیاد کراوە: بەبێ ئەمە دوو ئەنجامەکە بە یەکەوە دەنووسێن.
| 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. جووتەگوتە زۆر دەناسێتەوە. تاکەگوتە تەنها دووان دەناسێتەوە: \' (تاکەگوتەیەک) و '\\' (یەک لارەهێڵی پێچەوانە).
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ـدا دەشکێنێت، نەک لەسەر لاپەڕەی وێب.
| Sequenceهێما | Meaningواتا | In double quotesلە جووتەگوتەدا | In single quotesلە تاکەگوتەدا |
|---|---|---|---|
\n | New lineدێڕی نوێ | Worksکار دەکات | Printed as \nوەک \n چاپ دەبێت |
\t | Tabتاب | Worksکار دەکات | Printed as \tوەک \t چاپ دەبێت |
\r | Carriage 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کار دەکات |
<?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';
?>Line 1 Line 2 Price: $price = 5000 dinars She said "Hello" It's Aram's book One backslash: \ No new line here: \n
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
Line 1
Line 2<br>Price: $price = 5000 dinars<br>She said "Hello"<br>It's Aram's book<br>One backslash: \<br>No new line here: \nExplain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3
\nmakes a new line in the HTML that PHP sends, but the browser shows it as a space.\nلەو HTMLـەی PHP دەینێرێت دێڕی نوێ دروست دەکات، بەڵام وەک پیشانی دەدات.- Lineدێڕی 4
\$priceprints the dollar sign and the name;$priceprints the value.\$priceنیشانەی دۆلار و ناوەکە چاپ دەکات؛$priceچاپ دەکات.- Lineدێڕی 5
\"puts a double quote inside a double-quoted string.\"جووتەگوتەیەک دەخاتە ناو .- Lineدێڕی 8
In single quotes
\nis 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:
<?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';
?>Hello, World! Hello, $my_str! Hello\tWorld! Hello World! I'll be back
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
Hello, World!<br>Hello, $my_str!<br><pre>Hello\tWorld!</pre><pre>Hello World!</pre>I'll be backExplain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3
Double quotes:
$my_strbecomesWorld.جووتەگوتە:
$my_strدەبێت بەWorld.- Lineدێڕی 4
Single quotes:
$my_stris printed as it is.تاکەگوتە:
$my_strوەک خۆی چاپ دەبێت.- Lineدێڕی 7
Single quotes:
\tis two plain characters, a backslash and at.تاکەگوتە:
\tدوو ئاسایین، لارەهێڵی پێچەوانە وt.- Lineدێڕی 8
Double quotes:
\tbecomes 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:
پوختەی کۆرسەکە هەروەها \' لەناو جووتەگوتەدا تاقی دەکاتەوە. لەوێدا نییە، بۆیە لارەهێڵە پێچەوانەکە چاپ دەبێت:
<?php
echo "I\'ll do it\nH";
echo "<br>";
echo 'I\'ll do it\nH';
?>I\'ll do it H I'll do it\nH
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
I\'ll do it
H<br>I'll do it\nHExplain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
Double quotes:
\'stays as\', and\nbecomes a new line (shown as a space).جووتەگوتە:
\'وەک\'دەمێنێتەوە و\nدەبێت بە دێڕی نوێ (وەک پیشان دەدرێت).- Lineدێڕی 4
Single quotes:
\'becomes', and\nstays as two characters.تاکەگوتە:
\'دەبێت بە'و\nوەک دوو دەمێنێتەوە.
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') و وەک تاکەگوتە کار دەکات: هەموو شتێک ڕێک وەک خۆی چاپ دەکرێت.
<?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;
?>Hello, Hana! Welcome to Erbil. In a nowdoc, $name stays as it is.
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<p>Hello, Hana!</p>
<p>Welcome to Erbil.</p><p>In a nowdoc, $name stays as it is.</p>Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 5
<<<TEXTstarts a heredoc. The text runs until the lineTEXT;.<<<TEXTدەست پێ دەکات. دەقەکە تا دێڕیTEXT;بەردەوام دەبێت.- Lineدێڕی 6-7
As in double quotes,
$nameand{$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:
$nameis printed as written.هیچ شتێک ناگۆڕدرێت:
$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 .
بۆ ئەوەی دوو بکەیتە یەک، خاڵێک (.) لە نێوانیاندا دابنێ. ئەم کارە پێی دەوترێت . خاڵ ، وەک + بۆ ژمارەکان. نییە.
Joining strings (or lists) end to end. Python, Java and C# use +; PHP uses the dot operator . and .=.
بەیەکەوەلکاندنی (یان لیستەکان) لە دوای یەک. Python، Java و C# + بەکار دەهێنن؛ PHP کارپێکەری خاڵ . و .= بەکار دەهێنێت.
<?php
$string1 = "Hello World";
$string2 = "1234";
echo $string1 . " " . $string2;
?>Hello World 1234
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
Hello World 1234Explain 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:
پوختەی کۆرسەکە چوار ڕاستی دەربارەی دەڵێت. ئەم نموونەیە هەر چواریان پیشان دەدات:
<?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;
?>Hey AramHey Aram HelloWorld
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<p>Hey</p>AramHey<br>Aram<br>HelloWorldExplain 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$var2a 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ـدا هەڵدەگرێت. وانەکە پێی دەڵێت "ڕێگەیەکی تری ". ئەمە بۆ .
<?php
$firstString = "The quick brown tiger";
$secondString = " jumped over the lazy cat";
?>
<?php
$thirdString = $firstString;
$thirdString .= $secondString;
echo $thirdString;
?>The quick brown tiger jumped over the lazy cat
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
The quick brown tiger jumped over the lazy catExplain 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.
دووەم بخە کۆتاییەکەیەوە.
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 بنووسرێت ژمارەیەکی دەیدەییە.
<?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";
?>10
55
12
Fatal error: Uncaught TypeError: Unsupported operand types: string + string in C:\xampp\htdocs\plus.php:8
Stack trace:
#0 {main}
thrown in C:\xampp\htdocs\plus.php on line 8Each <br> is shown here as a new line.
لێرەدا هەر <br>ـێک وەک دێڕێکی نوێ پیشان دراوە.
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 aTypeError."Hello"ژمارە نییە، بۆیە PHP 8TypeErrorدەدات.
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] واتە تابی ڕاستەقینە و دێڕی نوێی ڕاستەقینە.
| Codeکۆد | The notes sayتێبینییەکان دەڵێن | Real output (PHP 8.5) ڕاستەقینە (PHP 8.5) | Commentتێبینی |
|---|---|---|---|
echo $var1.$var2; | Var1ValueVar2Value | Var1ValueVar2Value | Correct. The dot adds no space.دروستە. خاڵ هیچ زیاد ناکات. |
$var1 .= $var2; echo $var1; | Var1Value Var2Value | Var1ValueVar2Value | Wrong in the notes. .= adds no space either.لە تێبینییەکاندا هەڵەیە. .=ـیش هیچ زیاد ناکات. |
echo $var1.func1(); | Var1ValueFunc1Value | Var1ValueFunc1Value | Correct. The result of a can be joined too.دروستە. ئەنجامی دەکرێت بلکێنرێت. |
echo $var1." ".$var2; | Var1Value Var2Value | Var1Value Var2Value | Correct. The space comes from " ". (The notes used curly quotes.)دروستە. لە " "ـەوە دێت. (تێبینییەکان گوتەی چەماوەیان بەکارهێنابوو.) |
echo "$var1"; | Var1Value | Var1Value | Correct. Double quotes replace the variable.دروستە. جووتەگوتە دەگۆڕێت. |
echo '$var1'; | $var1 | $var1 | Correct. Single quotes print the name.دروستە. تاکەگوتە ناوەکە چاپ دەکات. |
echo "<pre>Hello\tWorld</pre>"; | Hello [tab] World | Hello[tab]World | Correct. \t becomes a tab.دروستە. \t دەبێت بە تاب. |
echo '<pre>Hello\tWorld</pre>'; | Hello\tWorld | Hello\tWorld | Correct. No escapes in single quotes.دروستە. لە تاکەگوتەدا نییە. |
echo "I\'ll do it\nH"; | I\'ll do it H | I\'ll do it[new line]H | Correct. The browser shows the new line as a space.دروستە. دێڕە نوێیەکە وەک پیشان دەدات. |
echo 'I\'ll do it\nH'; | I'll do it\nH | I'll do it\nH | Correct.دروستە. |
$var = 4; print($var = 5); | 5 | 5 | Correct. An has the assigned value, and print prints it.دروستە. هەمان ئەو کە دادەنرێت و print چاپی دەکات. |
echo true; | 1 | 1 | Correct. true prints as 1.دروستە. true وەک 1 چاپ دەبێت. |
echo !false; | 1 | 1 | Correct. !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 چاپی بکە یان لە هەڵیبگرە.
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";
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ـە.
<?php
echo strlen("Hello world!");
echo "<br>";
$firstString = "The quick brown tiger";
echo strlen($firstString);
echo "<br>";
echo strlen("Str");
echo "<br>";
echo strlen("");
?>12 21 3 0
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
12<br>21<br>3<br>0Explain 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.
چوار پیتە ئینگلیزییەکان گەورە یان بچووک دەکەن. هەر یەکەیان نوێ دەگەڕێنێتەوە؛ ناگۆڕێت.
| Function | What 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 تێکەڵ دەکات:
<?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); ?>Lower case: the quick brown tiger Upper case: THE QUICK BROWN TIGER Uppercase first-letter: The quick brown tiger Uppercase words: The Quick Brown Tiger
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<br />
Lower case:
the quick brown tiger<br />
Upper case:
THE QUICK BROWN TIGER<br />
Uppercase first-letter:
The quick brown tiger<br />
Uppercase words:
The Quick Brown TigerExplain 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() تەنها لە لای ڕاست (کۆتایی).
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 کراو پێکەوە دەلکێنێت. بە وردی سەیری ئەنجامەکە بکە:
<?php
$firstString = "The quick brown tiger";
$secondString = " jumped over the lazy cat";
echo $fourthString = $firstString . trim($secondString);
?>The quick brown tigerjumped over the lazy cat
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
The quick brown tigerjumped over the lazy catExplain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3
$secondStringstarts 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>ـدا چاپ دەکرێت، کە هەموو دیار دەهێڵێتەوە:
<?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>";
?>[ Aram Ali ] [Aram Ali] [Aram Ali ] [ Aram Ali] [A B]
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<pre>[ Aram Ali ]
[Aram Ali]
[Aram Ali ]
[ Aram Ali]
[A B]
</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() بیپشکنین، کە ڕێک و درێژییەکەی پیشان دەدات:
<?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>";
?>A B string(7) "A B" string(5) "A B" string(3) "A B"
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
A B<pre>string(7) "A B"
string(5) "A B"
string(3) "A B"
</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.
هەموو جۆرە لە دوو سەرەکەدا لادەبرێت.
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() هەمان کار دەکات بەڵام گوێ نادات بە گەورە و بچووکیی پیت.
<?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");
?>The super-fast brown tiger jumped over the lazy cat Web Programming BDilanB bonono Hello world Hello Kurdistan
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
The super-fast brown tiger jumped over the lazy cat<br>Web Programming<br>BDilanB<br>bonono<br>Hello world<br>Hello KurdistanExplain 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
Aare replaced, not only the first one.لە تێبینییەکانەوە: هەردوو پیتی
Aدەگۆڕدرێن، نەک تەنها یەکەمیان.- Lineدێڕی 10
All three
aletters becomeo.هەر سێ پیتی
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" دەدۆزێتەوە.
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) بە ئەو ژمارەیەی دیاری کراوە دووبارە دەکاتەوە و دەیگەڕێنێتەوە، بەبێ هیچ شتێک لە نێوان کۆپییەکاندا.
<?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);
?>AA ==================== The quick brown tiger jumped over the lazy catThe quick brown tiger jumped over the lazy cat
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
AA<br>====================<br>The quick brown tiger jumped over the lazy catThe quick brown tiger jumped over the lazy catExplain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3
From the notes:
"A"twice isAA.لە تێبینییەکانەوە:
"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) بە پێچەوانەوە دەگەڕێنێتەوە: دوایین دەبێتە یەکەم.
<?php
echo strrev("Hello world!");
echo "<br>";
echo strrev("12345");
?>!dlrow olleH 54321
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
!dlrow olleH<br>54321Built-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 دەڵێت لە کوێوە دەست بە گەڕان بکات؛ بەڵام شوێنە گەڕاوەکە هەر لە سەرەتای دەژمێردرێت.
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 ڕێگە بە دەدات کە لە کۆتاییەوە دەژمێرن.
strpos() returns an index; substr() uses one.هەر هەیە کە لە 0ـەوە دەست پێ دەکات. strpos() دەگەڕێنێتەوە؛ substr() بەکاردەهێنێت.CêIT<?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"));
?>6 10 0 6 bool(false)
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
6<br>10<br>0<br>6<br>bool(false)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 دەگەڕێنێتەوە.
<?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)";
}
?>Not found (wrong check) Found (right check) Found (str_contains)
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
Not found (wrong check)<br>Found (right check)<br>Found (str_contains)Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 5
strpos()returns 0 here.if (0)counts asfalse, so the wrong message is printed.strpos()لێرەدا 0 دەگەڕێنێتەوە.if (0)وەکfalseدادەنرێت، بۆیە پەیامە نادروستەکە چاپ دەبێت.- Lineدێڕی 12
0 !== falseis 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 و دواتر) تەنها بەڵێ یان نەخێر دەڵێت.
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ـە.
<?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"));
?>brown tiger jumped over the lazy cat zy cat Boys o Boys user bool(false)
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
brown tiger jumped over the lazy cat<br>zy cat<br>Boys<br>o Boys<br>user<br>bool(false)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 Boyswith a small o.یەکەم "o" لەناو "Hello"دایە، بۆیە ئەنجامەکە
o Boysـە بە o ـی بچووک.- Lineدێڕی 11
With
true: the part before the "@".لەگەڵ
true: ئەو بەشەی پێش "@".- Lineدێڕی 13
Not found:
false.نەدۆزرایەوە:
false.
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 واتە "سێ کۆتایی".
<?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);
?>uick brown world CDE CD llo
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
uick brown<br>world<br>CDE<br>CD<br>lloExplain 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 کۆتایی.
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().
explode() turns a into an ; implode() turns an array back into a string.explode() دەکات بە ؛ implode() دەکاتەوە بە .CêIT<?php
$str = "Web programming is easy to learn.";
print_r(explode(" ", $str));
?>Array ( [0] => Web [1] => programming [2] => is [3] => easy [4] => to [5] => learn. )
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
Array
(
[0] => Web
[1] => programming
[2] => is
[3] => easy
[4] => to
[5] => learn.
)print_r() prints an array. The page source has one element per line, but the browser shows everything on one line. Put echo "<pre>"; before it to keep the lines.
print_r() چاپ دەکات. لە کۆدی لاپەڕەکەدا هەر لەسەر دێڕێکە، بەڵام هەمووی لەسەر یەک دێڕ پیشان دەدات. پێش ئەوە echo "<pre>"; دابنێ بۆ ئەوەی دێڕەکان بمێننەوە.
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3
Split at every space. Each word becomes one element; the full stop stays with "learn.".
لە هەر لەتی بکە. هەر وشەیەک دەبێت بە ؛ خاڵەکە لەگەڵ "learn." دەمێنێتەوە.
<?php
$colors = explode(",", "red,green,blue");
echo $colors[0];
echo "<br>";
echo $colors[1];
echo "<br>";
echo count($colors);
?>red green 3
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
red<br>green<br>3Explain 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()دەڵێت چەند پارچە هەیە.
<?php
$input = array('Web', 'Programming', 'Simply', 'Easy', 'Learning');
echo join(" ", $input);
echo "<br>";
echo implode(" - ", $input);
?>Web Programming Simply Easy Learning Web - Programming - Simply - Easy - Learning
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
Web Programming Simply Easy Learning<br>Web - Programming - Simply - Easy - LearningExplain 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 بریتییە لە" - ".
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 . ناتوانیت هاش بگەڕێنیتەوە بۆ دەقە ڕەسەنەکە.
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() بۆ تێپەڕەوشە زۆر خێرا و لاوازن.
<?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."));
?>8b1a9953c4611296a827abf8c47804d7 5d41402abc4b2a76b9719d911017c592 32
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
8b1a9953c4611296a827abf8c47804d7<br>5d41402abc4b2a76b9719d911017c592<br>32Explain 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 نووسەیی دەدات.
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 < 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 دەکات بە و دەگەڕێنێتەوە. کۆدێکی کورتە وەک < کە وەک < پیشانی دەدات بەڵام هەرگیز وەک سەیری ناکات. بەم شێوەیە سەردانیکەر ناتوانێت یان خۆی بخاتە ناو لاپەڕەکەتەوە.
A short code that stands for a character in HTML, such as < for < or & for &. The browser shows the character but never treats it as part of a .
کۆدێکی کورتە کە لە HTMLـدا جێگەی نووسەیەک دەگرێتەوە، وەک < بۆ < یان & بۆ &. نووسەکە پیشان دەدات، بەڵام هەرگیز وەک بەشێک لە مامەڵەی لەگەڵ ناکات.
| Character | Becomesدەبێت بە |
|---|---|
& | & |
" | " |
' | ' |
< | < |
> | > |
<?php
$comment = "<b>Hi</b> & welcome";
echo $comment;
echo "<br>";
echo htmlspecialchars($comment);
?>Hi & welcome <b>Hi</b> & welcome
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<b>Hi</b> & welcome<br><b>Hi</b> & welcomeLook at the page source (html) and the page (preview): <b> is displayed as <b>.
سەیری کۆدی لاپەڕەکە (html) و خودی لاپەڕەکە (preview) بکە: <b> وەک <b> پیشان دەدرێت.
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() تەنها دەقێکی بێزیانە:
<?php
$comment = "<script>alert('Hacked!')</script>";
echo htmlspecialchars($comment);
?><script>alert('Hacked!')</script>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<script>alert('Hacked!')</script>Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3
The
<script>tag is converted, so it cannot run.<script>گۆڕدراوە، بۆیە ناتوانێت کار بکات.
<?php
echo htmlspecialchars("Tom & \"Jerry\" say 'hi' <3");
?>Tom & "Jerry" say 'hi' <3
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
Tom & "Jerry" say 'hi' <3Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
All five special characters are converted:
&,",',<and>.هەر پێنج دەگۆڕدرێن:
&،"،'،<و>.
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 پشکنراوە. هەر یەکێکیان یەک جار تاقی بکەرەوە!
| Function | What 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شوێنی یەکەم دۆزراوە، یان false | strpos("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>") | <b> |
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 و بە نیشانەی گوتەی ڕاست تاقی کردەوە. سێ لە تێبینییەکاندا هەڵەن؛ لە خوارەوە دیاری کراون.
| Code (as in the notes, straight quotes)کۆد (وەک تێبینییەکان، بە گوتەی ڕاست) | The notes sayتێبینییەکان دەڵێن | Real output (PHP 8.5) ڕاستەقینە (PHP 8.5) | Verdictبڕیار |
|---|---|---|---|
echo strToLower("Str"); | str | str | Correctدروستە |
echo strToUpper("Str"); | STR | STR | Correctدروستە |
$a = "ADilanA"; echo str_Replace("A", "B", $a); | BDilanB | BDilanB | Correct: every A is replacedدروستە: هەموو Aـیەک دەگۆڕدرێت |
echo str_Repeat("A", 2); | AA | AA | Correctدروستە |
echo strSTR("Hello Boys", "B"); | Boys | Boys | Correctدروستە |
echo strSTR("Hello Boys", "o"); | O Boys | o Boys | Wrong in the summary: the first o is the small o of "Hello"لە پوختەکەدا هەڵەیە: یەکەم o پیتی o ـی بچووکی ناو "Hello"ـە |
echo subSTR("ABCDEF", 2, 3); | CDE | CDE | Correct: start at index 2, take 3دروستە: لە 2ـەوە دەست پێ بکە، 3 وەربگرە |
echo subSTR("ABCDEF", 2, 2); | CD | CD | Correctدروستە |
echo strPOS("brown black", "b", 2); | 6 | 6 | Correct: the offset 2 skips the first bدروستە: offsetی 2 یەکەم b تێدەپەڕێنێت |
echo strChr("Hello", "He"); | Hello | Hello | Correctدروستە |
echo strChr("Hello", "e"); | ello | ello | Correctدروستە |
[BOOLEAN] | (no output given) | strchr("Hello", "e", true) → H | The third, boolean argument true returns the part before the match سێیەم کە ، واتە true، ئەو بەشەی پێش دۆزراوەکە دەگەڕێنێتەوە |
echo strLen("Str"); | 3 | 3 | Correctدروستە |
echo ucWords("str str"); | Str Str | Str Str | Correctدروستە |
echo ucFirst("str"); | Str | Str | Correctدروستە |
echo trim("A B"); | A B | A B | Wrong: inner spaces stay; only the browser hides themهەڵەیە: ناوەوە دەمێننەوە؛ تەنها دەیانشارێتەوە |
echo trim("A \t B"); | A B | A [tab] B | Wrong: the tab and spaces in the middle stayهەڵەیە: تاب و ناوەڕاست دەمێننەوە |
Common mistakesئەو هەڵانەی زۆر دەکرێن
- Curly quotes. Code copied from slides or a word processor often has “ ” or ‘ ’. PHP stops with a . Retype them as straight quotes.
- A missing
$.trim(secondString)makes PHP look for a constant and stop with anError. Writetrim($secondString). - Expecting the dot or
.=to add a space. They never do. Add" "yourself. - Joining with
+.+adds numbers;"Hello" + "World"is aTypeError. Use the dot. - Variables in single quotes.
'Hello $name'prints$name. Use double quotes or the dot. - Calling a function without using the result.
strtoupper($s);alone prints nothing. Useechoor store the result. - Thinking
trim()cleans the middle. It only removes whitespace at the two ends. - Testing
strpos()with a plainif. A match at position 0 looks like "not found". Use!== falseorstr_contains(). - Counting from 1. String positions start at 0: in
"ABCDEF",Cis at index 2. - Using
md5()for passwords. Usepassword_hash()andpassword_verify()instead. - Printing user input without
htmlspecialchars(). This opens the door to attacks. - Using a variable that was never set. PHP shows
Warning: Undefined variable. Give every variable a value first. - Using
strlen(),strrev()orstrtoupper()on Kurdish text. They work on bytes and English letters only. Use themb_functions, such asmb_strlen().
- نیشانەی گوتەی چەماوە. ئەو کۆدەی لە سلاید یان نەرمەکاڵای نووسینەوە کۆپی دەکرێت زۆرجار “ ” یان ‘ ’ـی تێدایە. PHP بە دەوەستێت. بە نیشانەی گوتەی ڕاست بیاننووسەرەوە.
$ـی ونبوو.trim(secondString)وا دەکات PHP بەدوای بگەڕێت و بەErrorبوەستێت. بنووسەtrim($secondString).- چاوەڕوانی ئەوە کە خاڵ یان
.=زیاد بکات. هەرگیز ناکەن. خۆت" "زیاد بکە. - لکاندن بە
+.+ژمارە کۆ دەکاتەوە؛"Hello" + "World"TypeErrorدەدات. خاڵ بەکاربهێنە. - لەناو تاکەگوتەدا.
'Hello $name'ناوی$nameچاپ دەکات. جووتەگوتە یان خاڵ بەکاربهێنە. - بانگکردنی بەبێ بەکارهێنانی ئەنجامەکەی.
strtoupper($s);بە تەنها هیچ چاپ ناکات.echoبەکاربهێنە یان ئەنجامەکە هەڵبگرە. - وا بیرکردنەوە کە
trim()ناوەڕاست پاک دەکاتەوە. تەنها لە دوو سەرەکە لادەبات. - پشکنینی
strpos()بەifـی سادە. دۆزراوەیەک لە شوێنی 0 وەک "نەدۆزرایەوە" دەردەکەوێت.!== falseیانstr_contains()بەکاربهێنە. - ژماردن لە 1ـەوە. شوێنەکانی لە 0ـەوە دەست پێ دەکەن: لە
"ABCDEF"ـداCلە 2دایە. - بەکارهێنانی
md5()بۆ . لە جیاتی ئەوەpassword_hash()وpassword_verify()بەکاربهێنە. - چاپکردنی بەبێ
htmlspecialchars(). ئەمە دەرگا بۆ هێرشی دەکاتەوە. - بەکارهێنانی کە هەرگیز پێ نەدراوە. PHP پەیامی
Warning: Undefined variableپیشان دەدات. سەرەتا بە هەموو بدە. - بەکارهێنانی
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 کاری پێ بکە. پێش ئەوەی کاری پێ بکەیت پێشبینی بکە، پاشان بەراوردی بکە.
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 دەکات بە تابی ڕاستەقینە. \' تاکەگوتەیەک دەخاتە ناو .
<?php
$my_str = 'World';
echo 'Hello, ' . $my_str . '!<br>';
?>Hello, World!
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
Hello, World!<br>Predict what this program prints, then run it. Where does the space between "Hello" and "World!" come from?
پێشبینی بکە ئەم چی چاپ دەکات، پاشان کاری پێ بکە. ئەو نێوان "Hello" و "World!" لە کوێوە دێت؟
<?php
$x = "Hello";
$y = " World!";
echo $x . $y; // Outputs: Hello World!
echo "<br>";
$x .= $y;
echo $x; // Outputs: Hello World!
?>Show answerوەڵامەکە پیشان بدە
<?php
$x = "Hello";
$y = " World!";
echo $x . $y; // Outputs: Hello World!
echo "<br>";
$x .= $y;
echo $x; // Outputs: Hello World!
?>Hello World! Hello World!
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
Hello World!<br>Hello World!Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 4
$x . $yjoins the two strings without changing$x.$x . $yدوو پێکەوە دەلکێنێت بەبێ گۆڕینی$x.- Lineدێڕی 7
$x .= $ychanges$xitself; 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!")؛ خاڵ هیچ زیاد ناکات.
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وەڵامەکە پیشان بدە
<?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);
?>WEB PROGRAMMING web programming Web programming Web Programming 16
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
WEB PROGRAMMING <br>web programming <br>Web programming <br>Web Programming <br>16Explain 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" و یەک بۆ کۆتایی.
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وەڵامەکە پیشان بدە
<?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);
?>12 !dlrow olleH 4 world! HELLO WORLD! Hello Kurdistan!
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
12<br>!dlrow olleH<br>4<br>world!<br>HELLO WORLD!<br>Hello Kurdistan!Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 7
The first
ois 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ڕاهێنانی زیاتر
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وەڵامەکە پیشان بدە
<?php
$name = " aRAM aLI ";
$clean = ucwords(strtolower(trim($name)));
echo $clean;
?>Aram Ali
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
Aram AliExplain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3
Functions can be nested: the innermost call runs first.
دەکرێت لەناو یەکتردا بن: ناوەوەترین بانگکردن یەکەم جار کار دەکات.
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وەڵامەکە پیشان بدە
<?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);
?>Looks like an email User: hana Domain: example.com
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
Looks like an email<br>User: hana<br>Domain: example.comExplain 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 orfalse; 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ـدا.
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.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.
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زاراوە سەرەکییەکان
Operatorsکارپێکەرەکان
Related lecturesوانە پەیوەندیدارەکان
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
- PHP Manual: Strings
- PHP Manual: String operators
- PHP Manual: String functions
- PHP Manual: strlen()
- PHP Manual: trim()
- PHP Manual: str_replace()
- PHP Manual: strpos()
- PHP Manual: strstr()
- PHP Manual: substr()
- PHP Manual: explode()
- PHP Manual: implode()
- PHP Manual: md5()
- PHP Manual: password_hash()
- PHP Manual: htmlspecialchars()
- PHP Manual: mb_strlen()
- MDN Glossary: Character reference (HTML entity)
- MDN Glossary: Cross-site scripting (XSS)
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.