Re: Explode and Trim
| From: | Joshua E Minnie | Date: | Fri, 05 Apr 2002 14:27:24 +0000 |
| Subject: | Re: Explode and Trim | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-91708@lists.php.net to get a copy of this message | ||
Unfortunately it doesn't. That is why I am kind of puzzled by the
situation.
--
Joshua E Minnie
CIO
josh@acsurf.net
"Don't work for recognition, but always do work worthy of recognition."
"Maxim Maletsky" <subscriptions@phpbeginner.com> wrote
>
> I think what yo wrote should be working fine for you.
>
> My way of your code:
>
>
>
>
> foreach(file($storelist) as $line_num=>$line_data) {
> foreach(explode(':', $line) as $key=>$val) {
> $val = trim($val); // remove whitespaces around
>
> // now you are inside each element of your
> multidimentional array
> // combine your rest of the code and work it out the way
> you need it.
>
> }
> }
>
>
>
> Sincerely,
>
> Maxim Maletsky
> Founder, Chief Developer
>
> PHPBeginner.com (Where PHP Begins)
> maxim@phpbeginner.com
> www.phpbeginner.com
>
>
> > -----Original Message-----
> > From: Joshua E Minnie [mailto:josh@acsurf.net]
> > Sent: Friday, April 05, 2002 1:07 AM
> > To: php-general@lists.php.net
> > Subject: [PHP] Explode and Trim
> >
> > 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
> > josh@acsurf.net
> >
> > "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
>
>