Tag Archives: function


Returns an array in which each element is a copy of the corresponding member of the current user-defined function’s argument list.

 function testFunction() {
 echo "Number of arguments : " .func_num_args();
testFunction(1, 2, 3);

It outputs Number of arguments : 3


This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.

The contents of this internal buffer may be copied into a string variable using ob_get_contents(). To output what is stored in the internal buffer, use ob_end_flush(). Alternatively, ob_end_clean() will silently discard the buffer contents.

 function callback($buffer) {
 return (str_replace("PHP", "PHP Codez", $buffer));
 <p>Welcome to PHP</p>

The output will be Welcome to PHP Codez


The quotemeta() function adds backslashes in front of some predefined characters in a string.

This function can be used to escape characters with special meanings, such as ( ), [ ], and * in SQL.

This function is binary-safe.

The predefined characters are:

  • period (.)
  • backslash (\)
  • plus sign (+)
  • asterisk (*)
  • question mark (?)
  • brackets ([])
  • caret (^)c
  • dollar sign ($)
  • parenthesis (())


 $str = "PHP Codez. (Welcome)";
 echo quotemeta($str);

It outputs PHP Codez\. \(Welcome\)


This function parses a URL and returns an associative array containing any of the various components of the URL that are present.

  • scheme – e.g. http
  • host
  • port
  • user
  • pass
  • path
  • query – after the question mark ?
  • fragment – after the hashmark #

This function is not meant to validate the given URL, it only breaks it up into the above listed parts. Partial URLs are also accepted, parse_url() tries its best to parse them correctly.

 $url = 'phpcodez.com/index.php?user=1';
 echo "<pre>";print_r(parse_url($url)); 
    [path] => phpcodez.com/index.php
    [query] => user=1


The preg_match_all() function matches all occurrences of pattern in string.

It will place these matches in the array pattern_array in the order you specify using the optional input parameter order. There are two possible types of order −

PREG_PATTERN_ORDER − is the default if the optional order parameter is not included. PREG_PATTERN_ORDER specifies the order in the way that you might think most logical; $pattern_array[0] is an array of all complete pattern matches, $pattern_array[1] is an array of all strings matching the first parenthesized regexp, and so on.

PREG_SET_ORDER − will order the array a bit differently than the default setting. $pattern_array[0] will contain elements matched by the first parenthesized regexp, $pattern_array[1] will contain elements matched by the second parenthesized regexp, and so on.

The function returns  the number of matching.

 $text = <<<EOT
 The big bang bonged under the bung.
 echo preg_match_all('@b.n?g@', $text, $matches);


This function checks if the given property exists in the specified class (and if it is accessible from the current scope).

It returns TRUE if the property exists, FALSE if it doesn’t exist or NULL in case of an error.

 $a = array('a'=>'a', 'b'=>'c');
 echo property_exists((object) $a, 'a')?'true':'false';

true-true will be the output