Tuesday, 26 July 2016

                           Sample question and answer 


1.What is PHP?
PHP is a server side scripting language commonly used for web applications.
PHP has many frameworks and cms for creating websites.

2.What is the use of "echo" in php?
It is used to print a data in the webpage, Example: <?php echo 'Car insurance'; ?>

3.How to include a file to a php page?
We can include a file using "include() " or "require()" function with file path as its parameter.

4.Differences between GET and POST methods ?
We can send 1024 bytes using GET method but POST method can transfer large amount of data and POST is the secure method than 
GET method .

5.How to declare an array in php?
Eg : var $arr = array('apple', 'grape', 'lemon');

6.What is use of in_array() function in php ?
in_array used to checks if a value exists in an array

7.What is use of count() function in php ?
count() is used to count all elements in an array, or something in an object

8.What’s the difference between include and require?
It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.

9.What is the difference between Session and Cookie?
The main difference between sessions and cookies is that sessions are stored on the server, and cookies are stored on the user’s computers in the text file format. Cookies can not hold multiple variables,But Session can hold multiple variables

10.How to set cookies in PHP?
Setcookie("sample", "ram", time()+3600);



11.How to Retrieve a Cookie Value?
eg : echo $_COOKIE["user"];

12.How to create a session? How to set a value in session ? How to Remove data from a session?
Create session : session_start();
Set value into session : $_SESSION['USER_ID']=1;
Remove data from a session : unset($_SESSION['USER_ID'];
['First_name'.]."<br/>";
}

13.How we can retrieve the data in the result set of MySQL using PHP?
1. mysql_fetch_row
2. mysql_fetch_array
3. mysql_fetch_object
4. mysql_fetch_assoc

14.What is the use of explode() function ?
Syntax : array explode ( string $delimiter , string $string [, int $limit ] ); 
This function breaks a string into an array. Each of the array elements is a substring of string formed by splitting it on boundaries formed by the string delimiter.

15.What is the difference between explode() and split() functions?
Split function splits string into array by regular expression. Explode splits a string into array by string.

16.What is the use of mysql_real_escape_string() function?
It is used to escapes special characters in a string for use in an SQL statement

17.Write down the code for save an uploaded file in php.
if ($_FILES["file"]["error"] == 0)
{
move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; 
}

18.How to create a text file in php?
$filename = "/home/user/guest/newfile.txt";
$file = fopen( $filename, "w" );
if( $file == false )
{
echo ( "Error in opening new file" ); exit();
}
fwrite( $file, "This is a simple test\n" );
fclose( $file );

19.How to strip whitespace (or other characters) from the beginning and end of a string ?
The trim() function removes whitespaces or other predefined characters from both sides of a string.

20.What is the use of header() function in php ?
The header() function sends a raw HTTP header to a client browser.Remember that this function must be called before sending the actual out put.For example, You do not print any HTML element before using this function.

21) How to upload file in PHP?

The move_uploaded_file() function is used to upload file in PHP.

bool move_uploaded_file ( string $filename , string $destination )    
More Details...

22) How to download file in PHP?

The readfile() function is used to download file in PHP.

int readfile ( string $filename )     
More Details...

23) How to delete file in PHP?

The unlink() function is used to delete file in PHP.

bool unlink (string $filename)      
More Details...

24) How to create connection in PHP?

The mysqli_connect() function is used to create connection in PHP.

resource mysqli_connect (server, username, password)       
More Details...

25) How to stop the execution of PHP script?

The exit() function is used to stop the execution of PHP script.

26) What are the popular Content Management Systems (CMS) in PHP?

WordPress
Joomla
Magento

Drupal etc.