strlen()
// function returns the length of a string.
echo strlen("Hello"); // outputs 5
• str_word_count()
// function counts the number of words in a string.
echo str_word_count("Hello world!"); // outputs 2
• strrev()
// function reverses a string.
echo strrev("Levani"); // outputs inaveL
• strpos()
/* function searches for a specific text within a string.
If a match is found, the function returns the character position of
the first match. If no match is found, it will return FALSE.*/
echo strpos("Hello world!", "l"); // outputs 2
// why ? index 0 = "H", index 1 = "e" and index 2 = "l"
• str_replace()
// function replaces some characters with some other characters in a string.
echo str_replace("l", "L", "levani"); // outputs Levani
• substr()
// function return part of a string between given indexes
echo substr("Hello world", 6)."\n"; // outputs world
echo substr("Hello world", 9, 2)."\n"; // outputs ld
echo substr("abcdef", -1)."\n"; // outputs f
echo substr("abcdef", -2)."\n"; // outputs ef
echo substr("abcdef", -3, 1)."\n"; // outputs d
• strtoupper()
// function make a string uppercase
echo strtoupper("i love coding")."\n"; // outputs I LOVE CODING
• strtolower()
// function make a string lowercase
echo strtolower("PHP")."\n"; // outputs php
• explode()
// function Split a string by a string
echo var_dump(explode(" ", "I am 19 years old"))."\n"; // outputs "I" "am" "19" ...
• implode()
// function join array elements with a string
echo implode(" ", ['Nika', 'Giorgi',"Saba"]); // outputs Nika Giorgi Saba
• trim()
// function strip whitespace (or other characters) from the beginning and end of a string
echo trim(" How are you ? ")."\n";
// outputs How are you ? (without any whitespace before and after the text)
pi()
// pi() function returns the value of PI:
echo pi(); // outputs 3.1415926535898
• min()
• max()
// min() and max() functions can be used to find the lowest or highest value in a list of arguments:
echo (min(1, 4, 35, -9, 48)); // outputs -9
echo (max(41, 12, 89, 23, -19)); // outputs 89
• abs()
// abs() function returns the absolute (positive) value of a number:
echo abs(-4.5); // outputs 4.5
• sqrt()
// sqrt() function returns the square root of a number:
echo sqrt(81); // outputs 9
• round()
// round() function rounds a floating-point number to its nearest integer:
echo round(1.7); // outputs 2
echo round(1.3); // outputs 1
• floor()
// floor() function rounds a number DOWN to the nearest integer:
echo floor(2.4); // outputs 2
echo floor(3.8); // outputs 3
echo floor(-1.1); // outputs -2
• rand()
// rand() function generates a random number:
echo rand();
// Alo we can add the optional min and max parameters to specify the lowest integer
// and the highest integer to be returned.
// For instance, random integer between 1 and 10 (inclusive), use rand(10, 100):
echo rand(1, 10);
• count()
// count() function returns the number of elements in an array:
$countries = array("Georgia","Ukraine","Spain");
echo count($countries); // outputs 3
• pow()
// pow() function returns x raised to the power of y. ( x = 2 , y = 3):
echo pow(2,3); // outputs 8
• decbin()
// decbin() function converts decimal to binary:
echo decbin(2);// outputs 10
echo "\n";
echo decbin(10); // outputs 1010
date_default_timezone_set('Asia/Tbilisi');
• d - Represents the day of the month (01 to 31)
echo date("d"); // outputs: current day of the month (01 to 31)
• D - A textual representation of a day (three letters)
echo date("D"); // outputs: currnet day (three letters)
• m - Represents a month (01 to 12)
echo date("m"); // outputs: current month (01 to 12)
• Y - Represents a year (in four digits)
echo date("Y"); // outputs: current year (in four digits)
• l - Represents the day of the week
echo date("l"); // outputs: current day (A full textual)
* echo "Today is " . date("Y/m/d"); // outputs: Today is 2022/10/17
echo "Today is " . date("Y.m.d"); // outputs: Today is 2022.10.17
echo "Today is " . date("Y-m-d"); // outputs: Today is 2022-10-17
echo "Today is " . date("l"); // outputs: Today is Monday
• H - 24-hour format of an hour (00 to 23)
echo date("H"); // outputs: current hour (00 to 23)
• h - 12-hour format of an hour with leading zeros (01 to 12)
echo date("h"); // outputs: currnet hour (01 to 12)
• i - Minutes with leading zeros (00 to 59)
echo date("i"); // outputs: current minutes (00 to 59)
• s - Seconds with leading zeros (00 to 59)
echo date("s"); // outputs: current seconds (00 four 59)
• a - Lowercase Ante meridiem and Post meridiem (am or pm)
echo date("a"); // outputs: current am/pm
$name = "Levani";
if ( $name == "Levani") {
echo "Condition is True !\n";
}
// "l" A full textual representation of the day of the week
if (date("l") == "Monday") {
echo "Let's start coding !\n";
}
$x = 10;
$y = 5;
if ($x > $y) {
echo "10 > 5\n";
}
if ($x < 2) {
// conditions is false
}
$x = 10;
if ($x > (2+4)) {
echo "Condition is True !\n";
} else {
echo "Condition is False !\n";
} // outputs: Condition is True !
if ($x < (2+4)) {
echo "Condition is True !\n";
} else {
echo "Condition is False !\n";
} // outputs: Condition is False !
$my_age = 19;
if ($my_age >= 18 ) {
echo "I am adult!";
} else {
echo "I am child!";
} // outputs: I am adult!
if (condition1){
//code to be executed if condition1 is true
} elseif (condition2){
//code to be executed if condition1 is false and condition2 is true
} elseif (condition3){
//code to be executed if condition2 is false and condition3 is true
....
} else{
//code to be executed if all given conditions are false
}
$x = 10;
if ($x > 0) {
echo "$x is positive\n";
} elseif ($x < 0 ) { // if $x equals negative number
echo "$x is negative!\n";
} else { // if $x = 0;
echo "$x is neither positive nor negative \n";
}