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:
  #1  
Old August 29th, 2002, 08:12 AM
MuuTuwon MuuTuwon is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Bloomington, IN, USA
Posts: 25 MuuTuwon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to MuuTuwon Send a message via AIM to MuuTuwon
Queston about splitting up something into an array


My queston is basicly, how do I take a string of characters and split them up into an array to where each character is a different element in the array.

The reason I want to know (In case someone has a better idea of how to handle this altogether), is to take the datetime stamp in mysql and echo it back in a format that makes a little more sense as a date and time(rather then 20020829011035).

I'm assuming to do that I'd have to have the entire thing broken into one array, but I have no idea how to do that. Then again there may be a ten times easier way that I know nothing about, I'm just a beginner afterall.

So any suggestions would be great, thanks ahead of time.

Reply With Quote
  #2  
Old August 29th, 2002, 08:37 AM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: Queston about splitting up something into an array

well you can use the date function to format the time stamp, to be more friendly to read. either way the answer to your question:
php Code:
Original - php Code
  1.  
  2. <?php
  3.  
  4. $string = "sometimes i pick my nose";
  5. $start = 0;
  6.  
  7. if($string{$start} != "")
  8. {
  9.     while($string{$start} != "")
  10.     {
  11.         $chars[] = $string{$start};
  12.         $start++;
  13.     }
  14. }
  15.  
  16. // your array of chars
  17. print_r($chars);
  18.  
  19. ?>

Reply With Quote
  #3  
Old August 29th, 2002, 02:22 PM
Matt Matt is offline
Contributing User
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: Queston about splitting up something into an array

Well, a string is essentially an array. You can access it as such:
php Code:
Original - php Code
  1. <?
  2. $string = "20020829011035";
  3. echo $string[5]; /* will echo 8 */
  4. ?>


As to an easier way to reformat the date, I haven't had very much like getting mysql datetime fields to parse well through strtotime (which is needed to produce a unix timestamp for the date function). A better bet is to use the built in date and time functions to mysql. With those, you can format the date however you wish with your SQL query.

Personally, I like storing dates in SQL as a unix timestamp...easier to work with in my opinion...

Reply With Quote
  #4  
Old August 29th, 2002, 06:18 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: Queston about splitting up something into an array

can you access it using $string[5]? i was under the impression that when referring to the elements of a string you needed to use curly brackets as follows $string{5}

:uhoh:

Reply With Quote
  #5  
Old August 29th, 2002, 06:36 PM
Matt Matt is offline
Contributing User
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: Queston about splitting up something into an array

You are right...using the []'s is deprecated, but still works. The {}'s are the proper syntax....

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Queston about splitting up something into an array


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT