Monday, August 10, 2015

PHP INTERVIEW

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

2. 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.
3.How to redirect a page in php?
The following code can be used for it, header("Location:index.php");

4. How stop the execution of a php scrip ?
exit() function is used to stop the execution of a page.

5.  How to set a page as a home page in a php based site ?
index.php is the default name of the home page in php based sites.

6.  How to find the length of a string?
strlen() function used to find the length of a string



No comments:

Post a Comment