PHP - Hypertext Preprocessor
PHP - Interview Questions
Q:What is PHP?
- PHP is a Server Side Scripting Language commonly used for Web Applications.
- PHP can be easily embedded into HTML.
- It is available for free and can be used accross variety of servers, operating systems and platforms.
Q:What is Session in PHP?
- Session allows data to be transfer from one page to another.
- Session information is temporary and information valid until the user is using the website.
- A Session assigns a unique ID, UID to each visitors.
eg:
Session Start »
<?php session_start(); ?>
Q:Difference between $message and $$message?
- $message - is a variable
- $message - is a variable of another variable
eg:
$message = "you";
$you = "hi";
echo $message; // output: you
echo $$message; // output: hi
$$message alows the developer to change the name of the variable dynamically.
Q:What is the difference between the functions unlink and unset?
Unlink is a function for file system handling which deletes a file.
Unset is used to destroy a variable.
Q:What is the difference between echo and print statement?
Echo can accept multiple expressions while print cannot.
echo is faster than print since it does not return a value.
Print returns 1 or 0 depending on the success.
Q:What is CAPTCHA?
CAPTCHA is a test to determine if the user using the system (usually a web form) is a human. It identifies this by throwing challenges to users. Depending on the responses the identification can be made. E,g Answering to identification of distorted images.
Q:How to upload files using PHP?
Files can be uploaded in PHP by using the tag type=”file”. An upload form must have encytype="multipart/form-data" , method also needs to be set to method="post". Also, hidden input MAX_FILE_SIZE before the file input. To restrict the size of files
E.g.
<form enctype="multipart/form-data" action="sampleuplaod.php"
method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1000" />
Q:What is the difference between using copy() and move() function in php file uploading?
Copy() makes a copy of the file. It returns TRUE on success. It can copy from any source to destination.
Move simple Moves the file to destination if the file is valid. While move can move the uploaded file from temp server location to any destination on the server. If filename is a valid upload file, but cannot be moved for some reason, no action will occur.
Q:What is the difference between mysql_fetch_object and mysql_fetch_array?
Mysql_fetch_object returns the result from the database as objects
mysql_fetch_array returns result as an array. This will allow access to the data by the field names.
E.g. using mysql_fetch_object field can be accessed as $result->name and using mysql_fetch_array field can be accessed as $result->[name]
Q:what is difference between "Primary key" and "Unique key"?
Primary key can't be null but unique key can be null.
Q:What is meant by nl2br()?
Inserts HTML line breaks (<BR />) before all newlines in a string.
Q:Some encryption method
AES_ENCRYT(), ENCODE(), DES_ENCRYPT(), ENCRYPT(), MD5(), OLD_PASSWORD(), PASSWORD(), SHA() or SHA1()
Q:What are the differences between public, private, protected,static, transient, final and volatile?
Public: Public declared items can be accessed everywhere.
Protected: Protected limits access to inherited and parent classes (and to the class that defines the item).
Private: Private limits visibility only to the class that defines the item.
Static: A static variable exists only in a local function scope,but it does not lose its value when program execution leaves this scope.
Final: Final keyword prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended.
Transient: A transient variable is a variable that may not be serialized.
Volatile: a variable that might be concurrently modified by multiple threads should be declared volatile. Variables declared to be volatile will not be optimized by the compiler because their value can change at any time.
Q:What is the functionality of the function strstr and stristr?
strstr Returns part of string from the first occurrence of needle(sub string that we finding out ) to the end of string.
$email= 'sonialouder@gmail.com';
$domain = strstr($email, '@');
echo $domain; // prints @gmail.com
here @ is the needle
stristr is case-insensitive means able not able to diffrenciate between a and A
0 comments:
Thanks for taking time to leave a comment