PHP Backslash handler function
Addslashes (): Adds a backslash to some predefined characters in the input string so that the processing is required for database query statements, and so on. These predefined characters are: Single quotes ('), double quotes ("), backslash (\), NULL.
Stripslashes (): Deletes the backslash that was added by the addslashes () function. This function is used to clean up data retrieved from a database or HTML form. (if two consecutive backslash, then remove one, keep one, if only a backslash, directly removed.) )
By default, the PHP directive MAGIC_QUOTES_GPC to on and automatically runs Addslashes () for all get, POST, and COOKIE data. Do not use Addslashes () on strings that have been escaped by MAGIC_QUOTES_GPC, because this can result in a double escape. You can use the function GET_MAGIC_QUOTES_GPC () for instrumentation when this situation is encountered. Cases:
if (GET_MAGIC_QUOTES_GPC ()) {
Code .....
}
|
Addslashes () Example:
<?php
$str = "Who ' s John Adams?";
Echo$str. " This isn't safe in a database query.<br/> ";
Echoaddslashes ($STR). " This is safe in a database query.
?>
|
Output results:
Who ' s John Adams? This isn't safe in a database query.
Who\ ' s John Adams? This is safe in a database query.
|
Stripslashes () Example:
<?php
Echostripslashes ("who\ ' s John Adams)";
?>
|
Output results:
--> --> -->