It determines whether a certain variable has already been declared by PHP. It returns a boolean value true if the variable has already been set, and false otherwise, or if the variable is set to the value NULL. or Determine if a variable is set and is not NULL.
example:
<?php
$var = '';
if (isset($var)) {
echo "This var is set so I will print.";
}
?>
<?php
$var = 0;
if (empty($var)) {
echo '$var is either 0, empty, or not set at all';
}
if (isset($var)) {
echo '$var is set even though it is empty';
}
?>
Output :
$var is either 0, empty, or not set at all.
$var is set even though it is empty.
htmlentities()
Whenever you allow your users to submit text to your website, you need to be careful that you don't leave any security holes open for malicious users to exploit. If you are ever going to allow user submitted text to be visible by the public you should consider using the htmlentities function to prevent them from running html code and scripts that may be harmful to your visitors.
The characters used in resource names, query strings, and parameters must not conflict with the characters that have special meanings or can't allowed in a URL. For example, a question mark character identifies the beginning of a query, and an ampersand (&) character separates multiple terms in a query. The meanings of these characters can be escaped using a hexadecimal encoding consisting of the percent character (%) followed by the two hexadecimal digits representing the ASCII encoded of the character. For example, an ampersand (&) character is encoded as %26.
The uniqid() function generates a unique ID based on the microtime (current time in microseconds).
example:
<?php
echo uniqid();
?>
Output :
4415297e3af8c (This value is not fixed,the value will change automatically each time)
md5()
The md5() function is used to calculate the md5 hash (the hash as a 32-character hexadecimal number ) of a string.
example:
<?php
$input_string = 'Good Morning';
echo 'Original string : '.$input_string.' ';
echo '16 bit binary format : '.md5($input_string, TRUE).' ';
echo '32 bit binary format : '.md5($input_string).' ';
?>
Output :
Original string : Good Morning
16 bit binary format :r y†” du?Û£¿ân
32 bit binary format : 72a079088694099d64753fdba3bfe26e
nl2br()
The nl2br() function inserts HTML line breaks in front of each newline (\n) in a string.
example:
<?php
echo nl2br("One line.\nAnother line.");
?>
Output :
One line.
Another line.
header()
* The header() function sends a raw HTTP header to a client.
* It is important to notice that header() must be called before any actual output is sent.
example:
<?php
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
?>
Original String : $99.99 and 10% tax
After encoded : %2499.99+and+10%25+tax
After decoded : $99.99 and 10% tax
ob_clean()
* Clean (erase) the output buffer.
error_reporting()
* Sets which PHP errors are reported.
example:
<?php
error_reporting(0);
// Turn off all error reporting
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Reporting E_NOTICE can be good too (to report uninitialized.
//variables or catch variable name misspellings ...)
error_reporting(E_ALL ^ E_NOTICE);
//Report all errors except E_NOTICE.
//This is the default value set in php.ini
error_reporting(E_ALL);
// Report all PHP errors (see changelog)
error_reporting(-1);
// Report all PHP errors
ini_set('error_reporting', E_ALL);
// Same as error_reporting(E_ALL);
?>
ini_set()
* Sets the value of a configuration option.
preg_match()
The preg_match() function Perform a regular expression match.
example:
<?php
// get host name from URL
preg_match('@^(?:http://)?([^/]+)@i',"http://www.php.net/index.html", $matches);
$host = $matches[1];
// get last two segments of host name
preg_match('/[^.]+\.[^.]+$/', $host, $matches);
echo "Domain name is: {$matches[0]}";
?>
<b>example: </b>, <div align=left>this is a test</div>
example: , this is a test Note :So, $out[0] contains array of strings that matched full pattern, and $out[1] contains array of strings enclosed by tags.
pathinfo()
* The pathinfo() function returns an array that contains information about a path.
* The following array elements are returned:
* The parse_str() function parses a query string into variables.
Note: If the array parameter is not set, variables set by this function will overwrite existing variables of the same name. Note: The magic_quotes_gpc setting in the php.ini file affects the output of this function. If enabled, the variables are converted by addslashes() before parsed by parse_str().
* The browser output of the code above will be:
Jane & 'Tarzan'
Jane & 'Tarzan'
Jane & 'Tarzan'
* If you select "View source" in the browser window, you will see the following HTML:
<html>
<body>
Jane & 'Tarzan'
Jane & 'Tarzan'
Jane & 'Tarzan'
</body>
</html>
Questions
What is the use of md5() and uniqid() ?
When to use urlencode() and urldecode() ?
What are required parameters of mail() ?
Given string is "Kapil Dev, Sunil Gavaskar, Sachin Tendulkar, Sourabh Ganguly, Rahul Dravid"
Write the code how many times the string "il" appears ?