Page 1 of 1

fgetcsv unreadable code

Posted: Wed Jun 02, 2010 8:51 pm
by guosheng1987
Hi guys.

I use fgetcsv like php manual
however it doesn't work correctly.

I can only get some unreadable code from the following function

what is more ,I also try setlocale(LC_ALL,'zh_CN'); in my script and nothing happened

my csv file is empty .

Code: Select all

function get_csv_contents( $file_target ){

	
	$handle  = fopen( $file_target, 'r');
	$contents = fgetcsv($handle, 10, ",");
	
	
	$coding = mb_detect_encoding($contents[0]);
	echo $coding;
	print_r($contents);

	echo $contents[0];

	fclose($handle);
}



$contents = get_csv_contents('test.csv');

any help will be appreciated

Re: fgetcsv unreadable code

Posted: Wed Jun 02, 2010 9:55 pm
by Benjamin
:arrow: Moved to PHP - Code

Re: fgetcsv unreadable code

Posted: Thu Jun 03, 2010 7:37 am
by phdatabase
To begin with, you only read one line of the csv file. Go back to the manual and check out the first example in the getcsv section. It does exactly what you are trying to do. http://us.php.net/manual/en/function.fgetcsv.php