schilly Posted October 7, 2010 Share Posted October 7, 2010 I'm inserting some data from a CSV file into a database. I'm using mysql_real_escape_string to escape a string and getting some really weird output. ex. input string = Adobe CS5 output = \0\0A\0d\0o\0b\0e\0 \0C\0S\05 I plugged the string into mb_detect_encoding and it told me it was in ASCII and I did a bunch of searching to find out that \0 is a null byte. The only thing I can't figure out is how to convert it to something that won't give me that garbage when I run it through mysql_real_escape_string. I tried mb_convert_encoding($str,"ISO-8859-1","ASCII") and it didn't do anything. Anyone know something I can try?? Quote Link to comment https://forums.phpfreaks.com/topic/215343-weird-output-from-mysql_real_escape_string/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 7, 2010 Share Posted October 7, 2010 You basically have two bytes per character, the upper byte being all zero bits, with an extra null byte at the start of the string. What is producing that data? Any chance that your code prior to that point is doing that? Another possibility is that you are transferring the file in binary mode instead of ascii mode. Quote Link to comment https://forums.phpfreaks.com/topic/215343-weird-output-from-mysql_real_escape_string/#findComment-1119834 Share on other sites More sharing options...
schilly Posted October 7, 2010 Author Share Posted October 7, 2010 This is CSV data cURL'd from Apple. I don't think it's my code: $fp = fopen($download_path,'r'); //remove first line with column info $data = fgetcsv($fp); $date = substr($file,0,10); //parse csv file while($data = fgetcsv($fp)){ #$data = str_replace(array('"','%','$'),'',$data); #error_reporting(E_ALL); #print_r($data); $app_name = $data[0]; echo $app_name = mysql_real_escape_string($app_name) . "\n\n"; } Could it be the data Apple sending me? Should I convert it before i save it to file? Quote Link to comment https://forums.phpfreaks.com/topic/215343-weird-output-from-mysql_real_escape_string/#findComment-1119839 Share on other sites More sharing options...
schilly Posted October 7, 2010 Author Share Posted October 7, 2010 Ok it's definitely straight from the data I'm getting via cURL. Is there an option for cURL I can set? Quote Link to comment https://forums.phpfreaks.com/topic/215343-weird-output-from-mysql_real_escape_string/#findComment-1119843 Share on other sites More sharing options...
schilly Posted October 7, 2010 Author Share Posted October 7, 2010 Here's is the content type in the header: Content-Type: text/csv;charset=UTF-16LE Quote Link to comment https://forums.phpfreaks.com/topic/215343-weird-output-from-mysql_real_escape_string/#findComment-1119844 Share on other sites More sharing options...
schilly Posted October 7, 2010 Author Share Posted October 7, 2010 Ok looks like I got it. mb_convert_encoding($data,'UTF-8','UTF-16LE') Thanks for putting me on the right path PFMaBiSmAd. Quote Link to comment https://forums.phpfreaks.com/topic/215343-weird-output-from-mysql_real_escape_string/#findComment-1119845 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.