Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

where is the data in this function?

Status
Not open for further replies.

someoneneedshelps

Technical User
Mar 3, 2016
75
GB
Wher is the data delimited by the ; in this function please?

Code:
	function csv_to_array()
	{
		$delimiter=';';
		$filename='auctions.csv';
		
		if(!file_exists($filename) || !is_readable($filename))
			return FALSE;
		
		$header = NULL;
		$data = array();
		if (($handle = fopen($filename, 'r')) !== FALSE)
		{
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
			{
				if(!$header)
					$header = $row;
				else
					$data[] = array_combine($header, $row);					
			}
			fclose($handle);
		}
		return $data;
	}
 
Wher is the data delimited by the ; in this function please?

I don't really understand your question, because the "data" is in the file that is specified in this $filename variable, not in the function.

And if it really is a CSV file (with comma separated values) the delimiter should be a comma ',' not a semicolon ';'

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
I can do comma or semi colon, point im making is a need to look at each column of data then wrap in quotes or dont wrap if int i hope thats clear, im goin to use join to put it back together
 
No idea what you mean,


Can I suggest that you ignore ALL your other threads on this same question and JUST STICK TO ONE of them.



You are confusing yourself and us by flitting from thread to thread with putting a bit of information in each of them.

Pick one to use, then "red flag" the rest for closing or deletion.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
I see this has a valid seperate question asking "where is the actual data" thats it, which is the bit that i can foreach($somedate as whateva)
abd echo each comma seperatted bit or does more code needed adding? Im new to php, i use to use asp which i found alot easier to understand but i have to stcik to php because of my platform

"Onward and upward
 
Im new to php


Which is WHY you need ALL the pertinent information for working out how to handle extracting data from a delimited file, the actual delimiter does not matter. You are jumping about getting bits of information and are having problems putting it all together.

I don't understand what you actually mean by "Wher is the data delimited by the ; in this function please?" because there is no "data in the function". It is a function for extracting the data from a source (a delimited string) and returns that extracted data in the form of an array.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top