PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old May 1st, 2002, 08:18 PM
dv8 dv8 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Mobile.Alabama
Posts: 32 dv8 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to dv8 Send a message via AIM to dv8
Explode() Question

When I have an exploded string. How do I break this Array into lines so that may be read individually?
php Code:
Original - php Code
  1.  
  2. $last_part = "INITIAL     24/2100Z 30.5N  49.5W    50 KTS
  3. 12HR VT     25/0600Z 31.0N  49.5W    50 KTS
  4. 24HR VT     25/1800Z 32.0N  50.0W    50 KTS
  5. 36HR VT     26/0600Z 33.0N  50.9W    50 KTS
  6. 48HR VT     26/1800Z 33.8N  52.0W    50 KTS
  7. 72HR VT     27/1800Z 34.5N  54.0W    50 KTS";

Reply With Quote
  #2  
Old May 1st, 2002, 08:32 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Explode() Question

Well, working with what you have posted, it looks like you have a newline character after each line that you would like as a seperate line. If that is always the case, you can use this:

$lines = explode("rn",$last_part);

that will place each line into a seperate array element and you can then address them as such:

php Code:
Original - php Code
  1.  
  2. echo $lines[0];
  3. echo $lines[1];
  4.  
  5. or
  6.  
  7. foreach($lines as $value) {
  8.    echo "$value<BR>n";
  9. }

Reply With Quote
  #3  
Old May 1st, 2002, 09:04 PM
dv8 dv8 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Mobile.Alabama
Posts: 32 dv8 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to dv8 Send a message via AIM to dv8
RE: Explode() Question

Darn... I see my mistake now.
I kept getting argument errors
Awesome thanks again!

Reply With Quote
  #4  
Old May 1st, 2002, 09:50 PM
dv8 dv8 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Mobile.Alabama
Posts: 32 dv8 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to dv8 Send a message via AIM to dv8
RE: Explode() Question

Does this break the lines up into a string or to another set of Arrays?
Well, at least the $lines are an Array...
Can I then explode() the $lines in seperate Arrays?

Reply With Quote
  #5  
Old May 1st, 2002, 09:54 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Explode() Question

That breaks $last_part down into an array called $lines which has each line in a seperate element. The end result would be as if you had done this:
php Code:
Original - php Code
  1.  
  2. $lines[0] = "INITIAL     24/2100Z 30.5N  49.5W    50 KTS";
  3. $lines[1] = "12HR VT     25/0600Z 31.0N  49.5W    50 KTS";
  4. $lines[2] = "24HR VT     25/1800Z 32.0N  50.0W    50 KTS";
  5. $lines[3] = "36HR VT     26/0600Z 33.0N  50.9W    50 KTS";
  6. $lines[4] = "48HR VT     26/1800Z 33.8N  52.0W    50 KTS";
  7. $lines[5] = "72HR VT     27/1800Z 34.5N  54.0W    50 KTS";



Reply With Quote
  #6  
Old May 1st, 2002, 11:09 PM
dv8 dv8 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Mobile.Alabama
Posts: 32 dv8 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to dv8 Send a message via AIM to dv8
RE: Explode() Question

The above is mine forgot to log in

Reply With Quote
  #7  
Old May 1st, 2002, 11:44 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Explode() Question

Now that I have the $lines Array.
Can I break up the Array again?
php Code:
Original - php Code
  1.  
  2. $lines[0] = "INITIAL     24/2100Z 30.5N  49.5W    50 KTS";
  3. $lines[1] = "12HR VT     25/0600Z 31.0N  49.5W    50 KTS";
  4. $lines[2] = "24HR VT     25/1800Z 32.0N  50.0W    50 KTS";
  5. $lines[3] = "36HR VT     26/0600Z 33.0N  50.9W    50 KTS";
  6. $lines[4] = "48HR VT     26/1800Z 33.8N  52.0W    50 KTS";
  7. $lines[5] = "72HR VT     27/1800Z 34.5N  54.0W    50 KTS";
  8.  
  9. //Convert to
  10. $parts[0] = "INITIAL";
  11. $parts[1] = "24/2100Z";
  12. $parts[2] = "30.5N";
  13. $parts[3] = "49.5W";
  14. $parts[4] = "50 KTS";
  15. //...etc....
  16.  


Reply With Quote
  #8  
Old May 1st, 2002, 11:52 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Explode() Question

Well, it appears that it is lined up by character count all the way. If this is the case for all your data, you can use substr()'s to get the data you want. I would have suggested just exploding it further but the amount of spaces in there makes that difficult. Actually what you could do is replace all sets of 5 spaces to 2 spaces. replace all sets of 4 spaces to 2 spaces, then replace all occurences of Z with Z plus a space. then explode with 2 spaces as your separator. If you want an example of that, let me know....


Reply With Quote
  #9  
Old May 2nd, 2002, 04:19 PM
dv8 dv8 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Mobile.Alabama
Posts: 32 dv8 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to dv8 Send a message via AIM to dv8
RE: Explode() Question

An example would be great, just so I know how to apply it. Thanks

Reply With Quote
  #10  
Old May 2nd, 2002, 04:53 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Explode() Question

Here you go, check this out...

php Code:
Original - php Code
  1.  
  2. <?
  3. $lines[0] = "INITIAL     24/2100Z 30.5N  49.5W    50 KTS";
  4. $lines[1] = "12HR VT     25/0600Z 31.0N  49.5W    50 KTS";
  5. $lines[2] = "24HR VT     25/1800Z 32.0N  50.0W    50 KTS";
  6. $lines[3] = "36HR VT     26/0600Z 33.0N  50.9W    50 KTS";
  7. $lines[4] = "48HR VT     26/1800Z 33.8N  52.0W    50 KTS";
  8. $lines[5] = "72HR VT     27/1800Z 34.5N  54.0W    50 KTS";
  9.  
  10.  
  11. $search = array("     ","    ","Z");
  12. $replace = array("  ","  ","Z ");
  13.  
  14.  
  15. $lines = str_replace($search,$replace,$lines);
  16.  
  17. for($i = 0;$i < count($lines); $i++) {
  18.     $parts[$i] = explode("  ",$lines[$i]);
  19. }
  20.  
  21. foreach($parts as $line) {
  22.     echo "<B>Echoing line.......</B><BR>n";
  23.     foreach($line as $piece) {
  24.         echo "$piece<BR>n";
  25.     }
  26.     echo "<BR>n";
  27. }
  28. ?>

Reply With Quote
  #11  
Old May 2nd, 2002, 05:07 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Explode() Question

Hmm... weird... I was using a FOR Statment but for some reason the first two Arrays were being exploded.
Eventhough, $i did return as Number(6). It only seemed to only count to Number(1).

Thanks again, Matt. Now to apply this to "EVERYTHING!!!" hahahaha Ok I'm getting to much power from this...

Reply With Quote
  #12  
Old May 2nd, 2002, 05:08 PM
dv8 dv8 is offline
Codewalkers Newbie (0 - 499 posts)