Results: 1580
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
➤ In this note we will look at some commonly used functions to manipulate strings. •
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)
by Levani Makhareishvili
2 years ago
0
PHP
Function
1
➤ In this note we will look at some commonly used math functions. •
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
by Levani Makhareishvili
2 years ago
0
PHP
Function
1
➤ The PHP date() function is used to format a date and/or a time. ➤ First of all, to get the right information, we need to set the default timezone:
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
by Levani Makhareishvili
2 years ago
0
PHP
Function
1
by nikoloz nachkebia
2 years ago
0
PHP
PHP Comments
1
➤ The if statement is used to execute a block of code only if the specified condition evaluates to true. For instance:
$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
}
by Levani Makhareishvili
2 years ago
0
PHP
If statement
1
by nikoloz nachkebia
2 years ago
0
PHP
echo statement
1
➤ The if...else statement executes some code if a condition is true and another code if that condition is false. For instance:
$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!
by Levani Makhareishvili
2 years ago
0
PHP
If...else statement
1
by დავით ქუთათელაძე
2 years ago
0
PHP
variable types
1
➤ The PHP if-else-if is a special statement used to combine multiple if...else statements. So, we can check multiple conditions using this statement.
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";
}
by Levani Makhareishvili
2 years ago
0
PHP
else if statement
1
by დავით ქუთათელაძე
2 years ago
1
PHP
array types
1
Results: 1580