myspacee Posted February 27, 2014 Share Posted February 27, 2014 Hello, i use Autoit for insert informations into mysql db Before that i use PHP but not fast as AI for Insert. Try to replicate a PHP function to text: mysql_real_escape_string this PHP function is a stringreplace for these cases : x00 n r ' " x1a anyone can post correct way to implement these text substitutions ? Thank you! m. Link to comment Share on other sites More sharing options...
mikell Posted February 27, 2014 Share Posted February 27, 2014 ? $str = '\x00\n\r\"\x1a' & "'" $str2 = StringRegExpReplace($str, '([\x00\\"\x1a\r\n''])', '\\$1') msgbox(0,"", $str &@crlf& $str2) Link to comment Share on other sites More sharing options...
myspacee Posted February 27, 2014 Author Share Posted February 27, 2014 thank you mikell, i hate compile StringRegExpReplace, I'm always afraid of making mistakes... why you set "replace"= '$1' ? (StringRegExpReplace ( "test", "pattern", "replace", [count] )) ? thank you again, m. Link to comment Share on other sites More sharing options...
mikell Posted February 27, 2014 Share Posted February 27, 2014 (edited) $1 is the backreference to the capturing group, and the backslash must be escaped itself (special character) $str = 'this is only a test' $str2 = StringRegExpReplace($str, '(only|test)', '\\$1') msgbox(0,"", $str &@crlf& $str2) Edited February 27, 2014 by mikell Link to comment Share on other sites More sharing options...
myspacee Posted February 28, 2014 Author Share Posted February 28, 2014 Thank you for support, so PHP function is not a simple text replacer, but it add escaping chars to given string... so to emulate PHP function this is bad : $str2 = StringRegExpReplace($str, '([\x00\\"\x1a\r\n''])', '') and this is right way ? $str2 = StringRegExpReplace($str, '([\x00\\"\x1a\r\n''])', '\\$1') I'm sorry, but i need an additional clarification; i'm replacing an old PHP script with a custom tool, and i must be sure to do it in best way possible. thank you again for your time, m. Link to comment Share on other sites More sharing options...
mikell Posted February 28, 2014 Share Posted February 28, 2014 I'm not familiar with mysql but googling "mysql_real_escape_string alternative" I got this : function mres($value) { $search = array("\\", "\x00", "\n", "\r", "'", '"', "\x1a"); $replace = array("\\\\","\\0","\\n", "\\r", "\'", '\"', "\\Z"); return str_replace($search, $replace, $value); } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now