fgetcsv unreadable code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
guosheng1987
Forum Newbie
Posts: 24
Joined: Thu Oct 15, 2009 3:03 am

fgetcsv unreadable code

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: fgetcsv unreadable code

Post by Benjamin »

:arrow: Moved to PHP - Code
User avatar
phdatabase
Forum Commoner
Posts: 83
Joined: Fri May 28, 2010 10:02 am
Location: Fort Myers, FL

Re: fgetcsv unreadable code

Post 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
Post Reply