Jump to content

CSV Parser


3s2ng

Recommended Posts

Hello Freaks,

I want to create a page like http://www.royalgojiteam.com/recognition_advancements.php but no database only CSV file.

How can I manage a page like that? The page is categories based on 1 field in the CSV in this case it the Title(ex. Royal Ambassadors, Ambassador V, etc.)

Sample Xls file:
[table]
[tr]
[td]Primary Last Name[/td]
[td]Primary First Name[/td]
[td]Secondary Last Name[/td]
[td]Secondary First Name[/td]
[td]Email[/td]
[td]Title[/td]
[td]State[/td]
[td]Password[/td]
[/tr]

[tr]
[td]McEachern[/td]
[td]Keith[/td]
[td]Secondary Last Name[/td]
[td]Secondary First Name[/td]
[td][email protected][/td]
[td]Royal Ambassador IV[/td]
[td]CT[/td]
[td]pwd[/td]
[/tr]

[tr]
[td]Estong[/td]
[td]Capio[/td]
[td][/td]
[td][/td]
[td][email protected][/td]
[td]Royal Ambassador[/td]
[td]AZ[/td]
[td]123[/td]
[/tr]
[/table]

Sample CSV
Primary Last Name,Primary First Name,Secondary Last Name,Secondary First Name,Email,Title,ST,Password
McEachern,Keith,,,[email protected],Royal Ambassador IV,CT,km5555
Moreland,Keith,,,[email protected],Royal Ambassador IV,CO,klmsmm

How can I parse the csv to be placed in that kind of layout?

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/22940-csv-parser/
Share on other sites

as long as you're not using incredibly large CSV files, you'll be fine. you'll still have to parse through each record to sort since there is no engine within a flat file to sort by or filter. check out fgetcsv() as well:
[code]
<?php
$handle = fopen("test.csv", "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 $data[$c] . "<br />\n";
  }
}
fclose($handle);
?>
[/code]

hope that helps
Link to comment
https://forums.phpfreaks.com/topic/22940-csv-parser/#findComment-103678
Share on other sites

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.