I am parsing through a text file and using explode to convert the string to
an array.  The problem seems to be at the end of the string, when I check to
see if the last element in the array is empty it tells me that it is not.
The problem comes because the last element should be empty because all that
was after the separator was white space.

---Sample text file---
AL:123 2nd Ave.:SomeCity:(123) 456-7890:(123) 456-1234:::
MI:293 3rd St.:Another City:(123) 345-2839:(123) 384-0398:::
MI:437 4th Ave.:Yet Another City:(123) 283-4839:(123) 458-4843:::
---End of text file---

---Code snippit---
$stores = file($storelist);
for($i=0; $i<count($stores); $i++) {
  //$stores[$i] = trim($stores[$i],"\r");
  //$stores[$i] = trim($stores[$i],"\n");
  //$stores[$i] = trim($stores[$i], ":");
  //$stores[$i] = rtrim($stores[$i]);
  echo $stores[$i]."<br><br>\n";
  $stores[$i] = explode(":", $stores[$i]);
}

reset($states);
while(current($states) && current($stores)) {
  for($i=0; $i<count($stores); $i++, next($stores)) {
    while($stores[$i][0] != key($states)) {
      next($states);
      $state = 0;
    }
    if($state==0) {
      echo "<b>".$states[$stores[$i][0]]."</b><br>\n";
      $state = 1;
    }
    echo $stores[$i][1].", ".$stores[$i][2]."<br>Phone:
".$stores[$i][3]."<br>Fax: ".$stores[$i][4]."<br>\n";
    if(!empty($stores[$i][5])) echo "Email: ".$stores[$i][5]."<br>\n";
    if(!empty($stores[$i][6])) echo "Web site: ".$stores[$i][6]."<br>\n";
    if(!empty($stores[$i][7]) && $stores[$i][7] != "") echo "Additional
notes: ".$stores[$i][7]."<br>\n";
    echo "<br>";
  }
}
---End of code snippit---

Here is the URL of where the code is being used:
www.wildwebtech.com/acs/nuven/stores.php.  The additional notes should only
show up if there were additional notes.

--
Joshua E Minnie
CIO
[EMAIL PROTECTED]

"Don't work for recognition, but always do work worthy of recognition."



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to