Jump to content


CSV Parser

  • Please log in to reply
4 replies to this topic

#1 3s2ng

  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 04 October 2006 - 02:22 AM

Hello Freaks,

I want to create a page like http://www.royalgoji...dvancements.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:

Primary Last NamePrimary First NameSecondary Last NameSecondary First NameEmailTitleStatePassword
McEachernKeithSecondary Last NameSecondary First Namekeithmceachern@aol.comRoyal Ambassador IVCTpwd
EstongCapiotest@aol.comRoyal AmbassadorAZ123

Sample CSV
Primary Last Name,Primary First Name,Secondary Last Name,Secondary First Name,Email,Title,ST,Password
McEachern,Keith,,,keithmceachern@aol.com,Royal Ambassador IV,CT,km5555
Moreland,Keith,,,free4lifekm@ris.net,Royal Ambassador IV,CO,klmsmm

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

Thanks in advance.

#2 AndyB

  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 04 October 2006 - 02:29 AM

file() reads the file into an array

explode("," ...) will explode each line into separate elements
Legend has it that reading the manual never killed anyone.
My site

#3 3s2ng

  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 04 October 2006 - 03:06 AM

Thanks for the Reply AndyB.

I want to display categorically.

Like if 1 listing has a title "Ambasador" I want to get that line and save it in an array. So it will display all listings with title "Ambassador" in the Ambassado category.

#4 3s2ng

  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 04 October 2006 - 12:48 PM

up please

#5 obsidian

  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 04 October 2006 - 12:58 PM

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:
$handle = fopen("test.csv", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
   $num = count($data);
   echo "<p> $num fields in line $row: <br /></p>\n";
   for ($c=0; $c < $num; $c++) {
       echo $data[$c] . "<br />\n";

hope that helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users