Last active
February 4, 2023 02:53
-
-
Save wilnaweb/ca37459bdf92aa74bd2dd7994fa5b0df to your computer and use it in GitHub Desktop.
Alternative mysql_real_escape_string without mysql connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Function | |
#Refer: https://www.php.net/manual/pt_BR/function.mysql-real-escape-string.php#101248 | |
function escape_string($param) { | |
if(is_array($param)) | |
return array_map(__METHOD__, $param); | |
if(!empty($param) && is_string($param)) { | |
return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $param); | |
} | |
return $param; | |
} | |
#Using example | |
$name = @trim(escape_string(stripslashes($_POST['name']))); |
The functions are similar, the difference is in the more complete character map in the recommended function.
%?
Better to use https://github.com/abreksa4/mysql-escape-string-polyfill/blob/master/src/functions.php
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
%?
Better to use https://github.com/abreksa4/mysql-escape-string-polyfill/blob/master/src/functions.php