The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications.
$date1 = date(‘Y-m-d’);
$date2 = ‘2006-07-01’;
$days = (strtotime($date1) – strtotime($date2)) / (60 * 60 * 24);
echo “Number of days since ‘2006-07-01’: $days”;
define (“MYCONSTANT”, 100);
urlencode() returns the URL encoded version of the given string. URL coding converts special characters into % signs followed by two hex digits.
urlencode(“10.00%”) will return “10%2E00%25”. URL encoded strings are safe to be used as part of URLs.
urldecode() returns the URL decoded version of the given string.
Uploaded file information is organized in $_FILES as a two-dimensional array as:
$_FILES[$fieldName][‘name’] – The Original file name on the browser system.
$_FILES[$fieldName][‘type’] – The file type determined by the browser.
$_FILES[$fieldName][‘size’] – The Number of bytes of the file content.
$_FILES[$fieldName][‘tmp_name’] – The temporary filename of the file in which the uploaded file was stored on the server.
$_FILES[$fieldName][‘error’] – The error code associated with this file upload.
MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array
Just like in C++, put an ampersand in front of it, like $a = &$b.
eregi_replace() function is identical to ereg_replace() except that it ignores case distinction when matching alphabetic characters.
func_num_args() function returns the number of parameters passed in.
Everything is passed by value.
DROP TABLE table_name – This will delete the table and its data.
TRUNCATE TABLE table_name – This will delete the data of the table, but not the table definition.
We can use the preg_match() function with “/.*@(.*)$/” as the regular expression pattern.
unlink() is a function for file system handling. It will simply delete the file in context.
unset() is a function for variable management. It will make a variable undefined.
The first one is octal 47, the second is hex 47.
We can create MySQL database with the use of mysql_create_db($databaseName) to create a database.
session_unregister() – Unregister a global variable from the current session
session_unset() – Free all session variables
a) sizeof($array) – This function is an alias of count()
b) count($urarray) – This function returns the number of elements in an array.
Interestingly if you just pass a simple var instead of an array, count() will return 1
MySQL SET function can take zero or more values, but at the maximum it can take 64 values.
SELECT COUNT(*) FROM table_name;
$result = mysql_query($any_valid_sql, $database_link);
$num_rows = mysql_num_rows($result);
echo “$num_rows rows found”;
CHAR is a fixed length data type. CHAR(n) will take n characters of storage even if you enter less than n characters to that column. For example, “Hello!” will be stored as “Hello! ” in CHAR(10) column.
VARCHAR is a variable length data type. VARCHAR(n) will take only the required storage for the actual number of characters entered to that column. For example, “Hello!” will be stored as “Hello!” in VARCHAR(10) column.
mysql_fetch_array – Fetch a result row as an associative array and a numeric array.
mysql_fetch_object – Returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead. Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows
mysql_fetch_row() – Fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.
htmlspecialchars() – Convert some special characters to HTML entities (Only the most widely used)
htmlentities() – Convert ALL special characters to HTML entities
image size use getimagesize() function
image width use imagesx() function
image height use imagesy() function
By the use of void set_time_limit(int seconds)
Abstract class: abstract classes are the class where one or more methods are abstract but not necessarily all method has to be abstract. Abstract methods are the methods, which are declare in its class but not define. The definition of those methods must be in its extending class.
Interface: Interfaces are one type of class where all the methods are abstract. That means all the methods only declared but not defined. All the methods must be define by its implemented class.
change maximum size of a file set upload_max_filesize variable in php.ini file
Expression preceding the ? is evaluated, if it’s true, then the expression preceding the : is executed, otherwise, the expression following : is executed.
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.
session_id() returns the session id for the current session.
They are both variables. But $message is a variable with a fixed name. $$message is a variable who’s name is stored in $message. For example, if $message contains “var”, $$message is the same as $var.
echo $_SERVER[‘HTTP_USER_AGENT’] . “\n\n”;
$browser = get_browser(null, true);
A session starts by session_start()function.
this session_start() is always declared in header portion.it always declares first.then
we write session_register().
Its intializing the object buffer, so that the whole page will be first parsed (instead of parsing in parts and thrown to browser gradually) and stored in output buffer so that after complete page is executed, it is thrown to the browser once at a time.
Here the Example
$x=”PHP is a ServerSide Scripting Language”;
list($month, $day, $year) = split(‘[/.-]’, $date);
Both are same while performing the action but using POST security is there.
Because using GET method in the action, form field values send along with URL, so at the time of sending password, problem will occur means password also will shown in the URL.
Using of POST there is no problem.
GET method has a limit of sending parameters 100 characters but POST method does not have a limit of sending data
GET is faster than POST. Because GET fetch the data directly from the URL but POST method fetch the encrypted data from the page.
The sprintf() function writes a formatted string to a variable.
42. What Is a Session?
Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.
43. What is the use of header() function in php?
The header() function is used for redirect the page.if you want to redirect one page to another we can use it.
44. How can i get ip address?
REMOTE_ADDR – the IP address of the client
REMOTE_HOST – the host address of the client
45. What is htaccess?
.htaccess files (or “distributed configuration files”) provide a way to make configuration changes on a per-directory basis.
46. What is the diffrence between Notify URL and Return URL?
Notify URL is used to just notify the status while processing.
Return URL is used to return after processing.
47. What is the difference between ucfirst and ucwords?
ucfirst() to convert the first letter of every string to uppercase, and ucwords(), to convert the first letter of every word in the string to uppercase.
48. What is meant by nl2br()?
nl2br() inserts a HTML tag <br> before all new line characters \n in a string.
49. How To Read the Entire File into a Single String?
$file = file_get_contents(“/windows/system32/drivers/etc/services”);
print(“Size of the file: “.strlen($file).”n”);
50. What are the different functions in sorting an array?
Sorting functions in PHP: