Webmaster

References : PHP 4.0

 | Index | 
 | Input/Output | General data handling | Array handling | String handling | Data conversion | Regular expressions | Time and date | PHP calendars | Configuration | 
 | All functions | 

General data handling

The functions introduced in this section are used for various data manipulations, such as checking a variable type, determining if it is set, converting its type, etc.

define(constant, value, case_insensitive) | defined(constant) | doubleval(expression) | empty(variable) | get_meta_tags(filename) | gettype(variable) | intval(expression) | is_array(variable) | is_double(variable) | is_integer(variable) | is_object(variable) | is_string(variable) | is_type(variable, type) | isset(variable) | settype(variable, type) | strval(variable) | unset(variable)

define(constant_name, value, case_insensitive)
Defines a named constant. You first declare a name and then the value it represents. If you don't want the name to be defined as case-sensitive, which is the default option, you have to specify the third parameter, case_insensitive, in the form of the TRUE boolean value. If the constant cannot be created for whatever reason or error, the result of the function will be FALSE (0).
 
Example<?
  define("COOKED", "Switch off the oven");
?>
 
 Top
defined(constant)
If the named constant has already been defined, the function results will be TRUE (1), otherwise it is FALSE (0).
 
Example<?
  define("COOKED","Switch off the oven");
    if(defined("COOKED"))
    {
    print("The constant exists.");
    }
?>
 
 Top
doubleval(variable)
Returns the float value of the variable. In any case, the result is a double.
 
Example<?
  $doublevar = "25 inch";
    print(doubleval($doublevar));
?>
 
 Top
empty(variable)
Used to determine if a variable has been set. The function result is TRUE if the variable has not received any value or has been assigned 0.
 
Example<?
  if(empty($townvar))
  {
      print("Unknown town");
  }
  else
  {
      print("The name of the town is known.");
  }
?>
 
 Top
get_meta_tags(filename)
Extracts all meta tag content attributes contained in the file referred to by the argument. In the array returned by the function, the properties declared with the name attribute become element keys and the corresponding content attribute values become element values.
 
Example<HTML>
<HEAD>
<TITLE>Meta example</TITLE>
<META name="description" content="Description to be indexed in a PHP array">
</HEAD>
<BODY>
<?
  get_meta_tags("filename.php");
?>
</BODY>
</HTML>
 
 Top
gettype(variable)
Returns a character string that gives the argument's data type. The following are the main strings that can be returned: integer, double, string, array, object, class, or unknown type.
 
Example<?
  printf("%s <br>\n", gettype("Hi"));
  printf("%s <br>\n", gettype(12));
  printf("%s <br>\n", gettype(8.3));
?>
 
 Top
intval(variable)
Returns the integer value of the argument.
 
Example<?
  $numstring = "25.8";
  intval($numstring);
?>
 
 Top
is_array(variable)
The function's result is TRUE if the argument is an array.
 
Example<?
  $frenchflag = array("blue", "white", "red");
    if(is_array($frenchflag))
    {
        print("This is indeed an array.");
    }
?>
 
 Top
is_double(variable)
Ascertains whether the passed argument is a floating point number, in which case the function's result is TRUE.
 
Example<?
  is_double(20.78);
?>
 
 Top
is_integer(variable)
Ascertains whether the passed argument is an integer, in which case the function's result is TRUE.
 
Example<?
  is_integer(2078);
?>
 
 Top
is_object(variable)
Ascertains whether the passed argument is an object, in which case the function's result is TRUE.
 
Example<?
  class Objectstruct
  {
      var $name;
  }
  $objref = new Objectstruct;

  if(is_object($objref))
  {
      print("This is indeed an object.");
  }
?>
 
 Top
is_string(variable)
Ascertains whether the passed argument is a string, in which case the function's result is TRUE.
 
Example<?
  is_string($author);
?>
 
 Top
is_type(variable, type)
The function's result is TRUE if the type of the first argument matches the type given as the second argument. There are six types available: integer, double, string, array, object et class.
 
Example<?
  is_type("hello", "string")
?>
 
 Top
isset(variable)
Ascertains whether a variable has been assigned a value, in which case the function's result is TRUE.
 
Example<?
  isset($var)
?>
 
 Top
settype(variable, type)
Converts the first argument's type to the type specified by the second argument. The function is TRUE if the conversion is successful. Here are the types available as the second argument: array, double, integer, object, string.
 
Example<?
  settype(20.78, "integer");
?>
 
 Top
strval(variable)
Converts the argument's value into its string equivalent.
 
Example<?
  strval(875241);
?>
 
 Top
unset(variable)
Destroys the variable passed as the argument in order to free the memory.
 
Example<?
  unset($var);
?>
 
 Top

 | Index | 
 | Input/Output | General data handling | Array handling | String handling | Data conversion | Regular expressions | Time and date | PHP calendars | Configuration | 
 | All functions |