PHP Interview Question & Answer

PHP Interview Question and Answer


21. 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

22. 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.

23. 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.

24. 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

25. 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"];
}

26. 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 );

27. 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.

28. 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.

29. How to redirect a page in php?

The following code can be used for it, header("Location:index.php");

30. How stop the execution of a php scrip ?

exit() function is used to stop the execution of a page


1 2 3 4 5 6