Category Archives: PHP

checkdate

It checks whether the date is valid or not

General Format :checkdate ( int $month , int $day , int $year )

Example :

<?php
if(checkdate(12, 31, 2000))
echo “Given Date Is Correct”;
?>

Output

Given Date Is Correct

Date functions

register_long_arrays

Its a flag and if its value is set to one we must use the longer version of the variable

Array Name Longer version of the name
$_POST $HTTP_POST_VARS
$_FILES $HTTP_POST_FILES
$_GET $HTTP_GET_VARS
$_COOKIE $HTTP_COOKIE_VARS
$_ENV $HTTP_ENV_VARS
$_SERVER $HTTP_SERVER_VARS
$_SESSION $HTTP_SESSION_VARS

Its not at all a convenient option , so its always better to have the value set to off

Unicode

Unicode is a computing industry standard for the consistent encoding, representation and handling of text expressed in most of the world’s writing systems. Developed in conjunction with the Universal Character Set standard and published in book form as The Unicode Standard, the latest version of Unicode consists of a repertoire of more than 109,000 characters covering 93 scripts, a set of code charts for visual reference, an encoding methodology and set of standard character encodings, an enumeration of character properties such as upper and lower case, a set of reference data computer files, and a number of related items, such as character properties, rules for normalization, decomposition, collation, rendering, and bidirectional display order

Unicode can be implemented by different character encodings. The most commonly used encodings are UTF-8, the now-obsolete UCS-2, and UTF-16. UTF-8 uses one byte for any ASCII characters, which have the same code values in both UTF-8 and ASCII encoding, and up to four bytes for other characters. UCS-2 uses two bytes for each character but cannot encode every character in the current Unicode standard. UTF-16 extends UCS-2, using four bytes to handle each of the additional characters.

Namespaces

Namespaces is a method with which we can group variable,function or objects so that we can have more than one variable or function or object with same name .

Namespaces were introduced into PHP from version 5.3 onwards

Example

<?php
namespace php;
class php
{
public function phpcodez()
{
echo ‘Function1 <br />’;
}
}
namespace codez;
class codez
{
public function phpcodez()
{
echo ‘Function2 <br />’;
}
}

$phpcodez = new phpphp();
$phpcodez->phpcodez();

$phpcodez = new codezcodez();
$phpcodez->phpcodez();

?>

Function

A function is a group of statements that will do certain tasks.

Why Function

When we develop a module in a project , we may need to implement certain tasks(block of statements ) more than once . Writing same block of codes more than once is not at all a good practice . Instead we can give a name to that block and can use them whenever necessary . When we define a block with a name , it is known as function .

General Format

function funation_name(){
echo “Error”; // can be on or more lines of statements
}

function – a keyword
funation_name – Any desired name(Should be meaningful)

Once the function is desfined , You can can invoke it by calling its name

<?php funation_name(); ?> // It will print the text “ Error”

A function can have arguments . When a fuction is define using arguments in it , we should pass the values when calling the it .

Example :
function function_sum($a,$b){
echo $a+$b;

}
<?php function_sum(7,8); ?> // It will display 15 as the result .

Note : We should not use any Builtin function name as the function name