PHP Interview Questions
1 .
Which functions are used to remove whitespaces from the string?
There are three functions in PHP to remove the whitespaces from the string.
 
trim() : It removes whitespaces from the left and right side of the string.
ltrim() : It removes whitespaces from the left side of the string.
rtrim() : It removes whitespaces from the right side of the string.

Exmple :
$str = " Tutorials for your help";
$val1 = trim($str);
$val2 = ltrim($str);
$val3 = rtrim($str);‚Äč
2 .
What is meant by public, private, protected, static and final scopes?
Public : Variables, classes, and methods which are declared public can be accessed from anywhere.

Private : Variables, classes and methods which are declared private can be accessed by the parent class only.

Protected : Variables, classes, and methods which are declared protected can be accessed by the parent and child classes only.

Static : The variable which is declared static can keep the value after losing the scope.

Final : This scope prevents the child class to declare the same item again.
3 .
Write a program using while loop
<?php
   $x = 1;
   while($x <= 5) {
    echo "The number is: $x <br>";
    $x++;
  }
?>
4 .
Distinguish between urlencode and urldecode?
This method is best when encode a string to used in a query part of a url. it returns a string in which all non-alphanumeric characters except -_. have replece with a percentege(%) sign . the urldecode->Decodes url to encode string as any % and other symbole are decode by the use of the urldecode() function.
5 .
Write down the code for save an uploaded file in php.
<?php
    if ($_FILES["file"]["error"] == 0)
   {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
   }
?>