timmah1 Posted September 29, 2008 Share Posted September 29, 2008 How can I find out the variable names from this csv? Here is what I have, it displays all the content with no problem, but I would like to be to know information is what Example name = GOOG I was looking around and found preg_match, to find out everything, but I have no idea how I would use it. <?php $row = 1; $handle = fopen("http://finance.yahoo.com/d/quotes.csv?s=GOOG&f=saa2a5bb6b4ncc1c3dd2d1eghs1e7xt6f6l2l3e1g4g1g3opk3ll1j1ij4p2p5mqrn4s7r5p1t7t1p6v1t8r1w1yvkjj5j6k4k5m3m7m8m4m6m5we9r6r7e8c8g6k2m2r2b2j3v724b3c6g5i5k1", "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { echo " $name" . $data[$c] . "<br />\n"; } } fclose($handle); ?> Any help would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/126316-variable-names/ Share on other sites More sharing options...
Psycho Posted September 29, 2008 Share Posted September 29, 2008 Need more information about the CSV. Are there name/value pairs on each line or what. If the name/value pairs are on each line such as: name1=value1 name2=value2 name3=value3 Then that is a simple procedure: $data = file('path/to/csvfile.csv'); foreach ($data as $line) { $nameValue = explode('=', $line); $name = trim($nameValue[0]); $value = trim($nameValue[1]); echo "Variable: $name, Value: $value<br />"; } //Output //Variable: name1, Value: value1 //Variable: name2, Value: value2 //Variable: name3, Value: value3 Link to comment https://forums.phpfreaks.com/topic/126316-variable-names/#findComment-653182 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.