It is used for sending email
<?php
function sendmail($to,$subject,$body,$from='admin',$cc='',$bcc=''){
$headers = "";
if($from){
$headers .= "From:$from\n";
}
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
if($cc){
$headers .= "Cc:$cc\n";
}
if($bcc){
$headers .= "Bcc:$bcc\n";
}
$headers .= "Message-ID: <". time() .rand(1,1000). "@".$_SERVER['SERVER_NAME'].">". "\n";
ini_set("sendmail_from", $from);
$msg =mail($to,$subject,stripslashes($body),$headers, "-f{$to}");
return $msg;
}
?>
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.
<?php
$var = '';
if (isset($var)) {
echo "This var is set so I will print.";
}
?>
Finds whether a variable is NULL.
<?php $foo = NULL; $inexistent=NULL; var_dump(is_null($inexistent), is_null($foo)); ?>
Determine whether a variable is empty.
<?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';
}
?>
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.
<?php $str = "Jane & 'Tarzan'"; echo htmlentities($str, ENT_COMPAT); ?>
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.
<?php
$userinput = urlencode('20?/30');
print "
".$userinput."
";
echo 'test';
?>
The uniqid() function generates a unique ID based on the microtime (current time in microseconds).
<?php echo uniqid(); ?>
The md5() function is used to calculate the md5 hash (the hash as a 32-character hexadecimal number ) of a string.
<?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).'
'; ?>
The nl2br() function inserts HTML line breaks in front of each newline (\n) in a string.
<?php
echo nl2br("One line.\nAnother line.");
?>
* 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.
<?php
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
?>
* Decodes URL-encoded string.
<?php $str = "$99.99 and 10% tax"; print "Original String : " .$str; print "
"; $encode = urlencode($str); print "After encoded : " .$encode; print "
"; $decode = urldecode($encode); print "After decoded : " .$decode; ?>
* Clean (erase) the output buffer.
* Sets which PHP errors are reported.
<?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);
?>
* Sets the value of a configuration option.
The preg_match() function Perform a regular expression match.
<?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]}";
?>
Perform a global regular expression match.
<?php
preg_match_all("|<[^>]+>(.*)[^>]+>|U","example: this is a test",$out, PREG_PATTERN_ORDER);
echo $out[0][0] . ", " . $out[0][1] . "\n";
echo $out[1][0] . ", " . $out[1][1] . "\n";
?>
* The pathinfo() function returns an array that contains information about a path.
* The following array elements are returned:
<?php
print_r(pathinfo("/testweb/test.txt"));
?>
<?php
print_r(pathinfo("/testweb/test.txt",PATHINFO_BASENAME));
?>
* 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.
<?php
parse_str("id=23&name=Kai%20Jim");
echo $id."
";
echo $name;
?>
<?php
parse_str("id=23&name=Kai%20Jim",$myArray);
print_r($myArray);
?>
* The htmlspecialchars() function converts some predefined characters to HTML entities.
* The predefined characters are:
& (ampersand) becomes &
" (double quote) becomes "
' (single quote) becomes '
< (less than) becomes <
> (greater than) becomes >
<?php $str = "Jane & 'Tarzan'"; echo htmlspecialchars($str, ENT_COMPAT); echo "
"; echo htmlspecialchars($str, ENT_QUOTES); echo "
"; echo htmlspecialchars($str, ENT_NOQUOTES); ?>
| After editing Click here: |
Output:
|
|
Hello World
|