Learn how to use php addslashes() function
In PHP, addslashes function is used to quote string with slashes. It 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).
For example, to insert the name O’reilly into a database, you will need to escape it. It’s highly recommended to use DBMS specific escape function (e.g. mysqli_real_escape_string() for MySQL or pg_escape_string() for PostgreSQL), but if the DBMS you’re using doesn’t have an escape function and the DBMS uses \ to escape special chars, you can use this function. 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 ‘.
addslashes
(PHP 4, PHP 5)
addslashes — Quote string with slashes
Syntax:
string addslashes ( string $str )
Parameters
str – The string to be escaped.
<?php $str = "Is your name O'reilly?"; // Outputs: Is your name O\'reilly? echo addslashes($str); ?>