Webmaster

References : PHP 4.0


Data conversion

The functions listed here allow you to format your data in order to improve your page presentation.

base64_decode(data) | base64_encode(string) | basename(path) | chop(string) | chr(ASCII_code) | dirname(path) | htmlentities(string) | htmlspecialchars | ltrim(string) | newline_to_br(string) | nl2br | ord(string) | parse_url(URL) | quotemeta(string) | rawurldecode(URL) | rawurlencode(URL) | stripslashes(string) | strrev(string) | strtolower(string) | strtoupper(string) | strtr(string, string_from, string_to) | trim(string) | ucfirst(string) | ucwords(string) | urldecode(URL) | urlencode(URL)

base64_decode(data)
Decodes data encoded with MIME base64, for instance, when binary files are sent through e-mail.
 
Example<?
  $file = "YUVf8djrYEkd45dhe7lLe78qa5etTAre7PrT1KFcF4";
  base64_decode($file);
?>
 
 Top
base64_encode(string)
Returns data encoded with base64, for instance, when binary files need to be sent through e-mail.
 
Example<?
  $string = "Here is a message\n";
  base64_encode($string);
?>
 
 Top
basename(path)
Returns the filename part of a string containing a whole path to a file.
 
Example<?
  $path="/doc/users/dino/liste.asc";
  print(basename($path));
?>
 
 Top
chop(string)
Returns the string passed as the argument with white spaces stripped from the end.
 
Example<? print("\"" .chop("A sentence with a lot of trailing white spaces     ")."\""); ?>
 
 Top
chr(ASCII_code)
Returns the character corresponding to the ASCII code passed as the argument.
 
Example<? print(chr(28)); ?>
 
 Top
dirname(path)
Returns the directory portion of a filename qualified by a path.
 
Example<?
  $path = "/doc/users/dino/liste.asc";
  dirname($path);
?>
 
 Top
htmlentities(string)
Translates all the characters that have HTML character entity equivalents into these entities. Here are the character entity references recognised by this function: aacute, acirc, acute, aelig, agrave, amp, aring, atilde, auml, brvbar, ccedil, cedil, cent, copy, curren, deg, divide, eacute, ecirc, egrave, eth, euml, frac12, frac14, frac34, gt, iacute, icirc, iexcl, igrave, iquest, iuml, laquo, lt, macr, micro, middot, nbsp, not, ntilde, oacute, ocirc, ograve, ordf, ordm, oslash, otilde, ouml, para, plusmn, pound, quot, raquo, reg, sect, shy, sup1, sup2, sup3, szlig, thorn, times, uacute, ucirc, ugrave, uml, uuml, yacute, yen, yuml.
 
Example<?
  $var = "Not all keyboards have the é and ŕ keys.";
  htmlentities($var);
?>
 
 Top
htmlspecialchars(string)
Similar to htmlentities but for a more limited set of characters.
 
 Top
ltrim(string)
Strips all white spaces from the beginning of a string.
 
Example<?
  $var = "     A sentence beginning with white spaces.";
  ltrim($var);
?>
 
 Top
newline_to_br(string)
Returns the string passed as the argument with new line characters replaced by the BR HTML element. If this function does not exist in your version of PHP, use the nl2br() alias.
 
Example<?
  $var = "line1\nline2\n";
  print(newline_to_br($var));
?>
 
 Top
nl2br(string)
Similar to the newline_to_br function.
 
 Top
ord(string)
Returns the ASCII value of the first character appearing in the argument.
 
Example<? print(ord("m")); ?>
 
 Top
parse_url(URL)
This function parses the URL passed as the argument and returns its components in an associative array. Here are the main elements returned: scheme, host, path et query.
 
Example<?
  $query = "http://www.mysite.com";
  $query .= "/folder/analyse.php3?";
  $query .= "name=henry&work=London+Engineer";
  $url = parse_url($query);
?>
 
 Top
quotemeta(string)
Returns the string passed as the argument after adding a backslash character before each of the following special characters: ., \, +, *, ?, [, ], ^, (, ), $.
 
Example<?
  $command = "echo 'Hello, how are you?'";
  quotemeta($command);
?>
 
 Top
rawurldecode(URL)
Returns the URL passed as the argument after replacing the sequences of the percentage sign followed by two hexadecimal digits by their corresponding literal characters.
 
Example<? print(rawurldecode("mailto:peter%40mysite.com")); ?>
 
 Top
rawurlencode(URL)
Returns the string passed as the argument after replacing all special characters with their corresponding hexadecimal value prefixed with a percentage sign.
 
Example<? rawurlencode("mailto:peter@mysite.com"); ?>
 
 Top
stripslashes(string)
Returns the argument with all the backslashes stripped from the escaped characters.
 
Example<? print(stripslashes("The \'head\' HTML element")); ?>
 
 Top
strrev(string)
Returns a string after reversing its characters.
 
Example<? print(strrev("abcdefg")); ?>
 
 Top
strtolower(string)
Returns the string passed as the argument with all the alphabetical characters converted into lowercase letters.
 
Example<? print(strtolower("I Took 5 Kilos")); ?>
 
 Top
strtoupper(string)
Returns the string with all the alphabetical characters converted into uppercase letters.
 
Example<? print(strtoupper("I took 5 kilos")); ?>
 
 Top
strtr(string, string_from, string_to)
Returns the string argument after replacing the characters listed in string_from by the corresponding characters in string_to.
 
Example<?
  $string = "Oops! I see.";
  $string_from = "!.";
  $string_to = "?!";

  print(strtr($string, $string_from, $string_to));
?>
 
 Top
trim(string)
Strips all the beginning and trailing white spaces from the string. This is very useful for cleaning data collected from a form before inserting them in a database.
 
Example<?
  $var = "    data    ";
  trim($var);
?>
 
 Top
ucfirst(string)
Converts the first character of the argument into the upper case.
 
Example<? print(ucfirst("paris is the capital of France.")); ?>
 
 Top
ucwords(string)
Converts the first letter of each word in the string into the upper case.
 
Example<? print(ucwords("paris is the capital of france.")); ?>
 
 Top
urldecode(URL)
Returns an URL-encoded string after decoding all the percentage signs followed by two hexadecimal digits.
 
Example<? print(urldecode("mailto:peter%40mysite.com")); ?>
 
 Top
urlencode(URL)
Returns the URL passed as the argument after replacing all non-alphabetical characters by a percentage sign followed by two hexadecimal digits and space characters by a plus sign.
 
Example<? print(urlencode("peter@mysite.com")); ?>
 
 Top