Jump to content

weird output from mysql_real_escape_string


schilly

Recommended Posts

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??

 

 

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.

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?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.