Results: 1578
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
String Functions
<?php

   # String Functions

     // Function strlen() returns the length of the string, example:
      echo strlen ("Nice to meet you!") . "\n"; /* output - 17 */

     // Function strrev() returns the Reverse of the string, example:
      echo strrev ("Nice to meet you!") . "\n"; /* output - !uoy teem ot eciN */

     // Function strpos() tries to find the second parameter and returns its index. example:
      echo strpos ("Nice to meet you", "you") . "\n"; /* output - 13 */;

     // Function str_replace() replaces the word "Hello" with "Hi" , example:
      echo ("Hello", "Hi", "Hello there") . "\n"; // outputs - Hi there;

     // Function substr() returns the substring between given indexes, example:
      echo substr("Nice to meet you", "5") . "\n"; // outputs - to meet you;
      echo substr("Nice to meet you", 5, 3) . "\n"; // outputs - to meet you;

     // Function trim() removes whitespaces from sides of the string, example:
      echo trim("  Nice to meet you  ") . "\n"; // outputs - Nice to meet you;

     // Function strtoupper() converts the string to upper case, example:
      echo strtoupper("Nice to meet you") . "\n"; //outputs - NICE TO MEET YOU;
    
    // Function strtolower() converts the string to lower case, example:
      echo strtolower("NICE To Meet You") ; //outputs - nice to meet you;
    
    // Function explode() breaks the string by its delimiter, example:
      print_r (explode(" ", "It's the first day of the course!"));
    
    // Function implode() joins the array element based on the delimiter and returns the string, example:
      echo implode(" ", ['Nice', 'to', 'meet', 'you']); //outputs - Nice to meet you;

    // The PHP str_word_count() function counts the number of words in a string, example:
      echo str_word_count("Nice to meet you!"); // outputs - 4
?>
by Mariam Gelkhauri
3 years ago
0
PHP
String Functions
Object Oriented PHP Tutorial
0
➤ The PHP arithmetic operators are used with numeric values to perform common arithmetical operations. For instance:
$x = 100;
$y = 11;
• Addition (Sum of $x and $y)
echo $x + $y . "\n";
• Subtraction (Difference of $x and $y)
echo $x - $y . "\n";
• Multiplication (Product of $x and $y)
echo $x * $y . "\n";
• Division (Quotient of $x and $y)
echo $x / $y . "\n";
• Modulus (Remainder of $x divided by $y)
echo $x % $y . "\n";
• Exponentiation (Result of raising $x to the $y'th power)
echo $x ** $y . "\n";
by Levani Makhareishvili
3 years ago
0
PHP
Operators
1
• A variable must start with a dollar ($) sign. • It can only contain alpha-numeric character and underscore (A-z, 0-9, _). • A variable name must start with a letter or underscore (_) character. • A PHP variable name cannot contain spaces. • One thing to be kept in mind that the variable name cannot start with a number or special symbols. • PHP variables are case-sensitive, so $name and $NAME both are treated as different variable. Incorrect syntax:
name = "No name";
$1x = 20;
$)name = "No name";
$na me = "Hola";
&na-me = "Hello";
Correct syntax:
$name = "No name";
$x1 = 20;
$_name = "Hello";
by Levani Makhareishvili
3 years ago
0
PHP
variables
1
by დავით ქუთათელაძე
3 years ago
0
PHP
php comments
1
by დავით ქუთათელაძე
3 years ago
0
PHP
Comparison operators
1
by დავით ქუთათელაძე
3 years ago
0
PHP
Assignment operators
1
by დავით ქუთათელაძე
3 years ago
0
PHP
Arithmetic operators
1
A variable starts with the
$
sign. For instance:
$firstname = "Levani"; 
$lastname = "Makhareishvili";
$age = 19;
• Assignment Operator (=) is used to assign the value to a variable. • the variable $firstname will hold the value "Levani", • the variable $lastname will hold the value "Makhareishvili" and so on. To output the variable on the screen, we write the name of the variable:
echo $age;
When we want to output the value of the variable together with the text, we write the name of the variable in double quotes or after the text we write a comma or a dot and then the name of the variable:
echo "My name is $firstname $lastname, I am $age years old";
echo "My name is ",$firstname," ",$lastname,", I am ".$age. " years old.";
! PHP statements end with semicolons (;).
by Levani Makhareishvili
3 years ago
0
PHP
variables
1
by დავით ქუთათელაძე
3 years ago
0
PHP
php variables
1
increment-decrement
$x++; // equivalent to $x = $x+1;
$x--; // equivalent to $x = $x-1; 
$x++; // post-increment 
$x--; // post-decrement 
++$x; // pre-increment 
--$x; // pre-decrement
The difference is that the post-increment returns the original value before it changes the variable, while the pre-increment changes the variable first and then returns the value. Example:
$a  = 2; $b = $a++; // $a=3,  $b=2
$a  = 2; $b = ++$a; // $a=3,  $b=3
by Guram Azarashvili
3 years ago
0
PHP
PHP official doc
0
Results: 1578