Wednesday, January 24, 2007

php - bin2hex function

bin2hex

(PHP 3 >= 3.0.9, PHP 4, PHP 5)
bin2hex -- Convert binary data into hexadecimal representation
Description
string bin2hex ( string str )

Returns an ASCII string containing the hexadecimal representation of str. The conversion is done byte-wise with the high-nibble first.

php - addslashes function

addslashes

(PHP 3, PHP 4, PHP 5)
addslashes -- Quote string with slashes
Description
string addslashes ( string str )

Returns a string with backslashes before characters that need to be quoted in database queries etc. These characters are single quote ('), double quote ("), backslash (\) and NUL (the NULL byte).

An example use of addslashes() is when you're entering data into a database. For example, to insert the name O'reilly into a database, you will need to escape it. Most databases do this with a \ which would mean O\'reilly. This would only be to get the data into the database, the extra \ will not be inserted. Having the PHP directive magic_quotes_sybase set to on will mean ' is instead escaped with another '.

The PHP directive magic_quotes_gpc is on by default, and it essentially runs addslashes() on all GET, POST, and COOKIE data. Do not use addslashes() on strings that have already been escaped with magic_quotes_gpc as you'll then do double escaping. The function get_magic_quotes_gpc() may come in handy for checking this.

Example (1):
<?php
$str = "Is your name O'reilly?";

// Outputs: Is your name O\'reilly?
echo addslashes($str);
?>

php - addcslashes function

addcslashes

(PHP 4, PHP 5)
addcslashes -- Quote string with slashes in a C style
Description
string addcslashes ( string str, string charlist )

Returns a string with backslashes before characters that are listed in charlist parameter. If charlist contains characters \n, \r etc., they are converted in C-like style, while other non-alphanumeric characters with ASCII codes lower than 32 and higher than 126 converted to octal representation.

Be careful if you choose to escape characters 0, a, b, f, n, r, t and v. They will be converted to \0, \a, \b, \f, \n, \r, \t and \v. In PHP \0 (NULL), \r (carriage return), \n (newline) and \t (tab) are predefined escape sequences, while in C all of these are predefined escape sequences.

charlist like "\0..\37", which would escape all characters with ASCII code between 0 and 31.

Example (1):


<?php
echo addcslashes('foo[ ]', 'A..z');
// output: \f\o\o\[ \]
// All upper and lower-case letters will be escaped
// ... but so will the [\]^_` and any tabs, line
// feeds, carriage returns, etc.
?>


Welcome to Help

Welcome to PHP phpphpphp.blogspot.com : Your PHP Help Center!

This website exists to provide you with information to use while learning or developing PHP and MySQL. If you need PHP Help or you would like to provide PHP Help to other developers, you are in the right place. Additionally, we offer Apache Help, MySQL Help, Javascript Help, CSS Help, XML Help and much more.

This is a community website and we ask that you join to gain access to our interactive features and also assist others by sharing your knowledge about PHP and MySQL.