Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > how php can parse based on ","

how php can parse based on ","
Thread Tools
Registered User
Join Date: Sep 2002
Location: New York City
Status: Offline
Reply With Quote
Jul 11, 2004, 02:30 PM
 
Hi all,

I'm sure there is a simple solution to my problem, but I'm kinda limited for time, so I would greatly appreciate any advice or tips.

I have a string: a,b,c,d,e

Using PHP...What is the easiest way to quickly parse the string and break the values into an array, so that:
myarray[1] = 'a'
myarray[2] = 'b'
myarray[3] = 'c'
myarray[4] = 'd'
myarray[5] = 'e'

Thanks in advance.

-Ben
     
Professional Poster
Join Date: Oct 2001
Status: Offline
Reply With Quote
Jul 11, 2004, 02:49 PM
 
Originally posted by bens1901:
Hi all,

I'm sure there is a simple solution to my problem, but I'm kinda limited for time, so I would greatly appreciate any advice or tips.

I have a string: a,b,c,d,e

Using PHP...What is the easiest way to quickly parse the string and break the values into an array, so that:
myarray[1] = 'a'
myarray[2] = 'b'
myarray[3] = 'c'
myarray[4] = 'd'
myarray[5] = 'e'

Thanks in advance.

-Ben
Use the 'explode()' function. i.e:
[php]$mystring = "a,b,c,d,e";
$myarray = explode(",", $mystring);[/php]

http://us4.php.net/manual/en/function.explode.php for more info.
     
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
Jul 11, 2004, 05:30 PM
 
Pedantic note:

PHP (like many languages) starts numbering its arrays at 0, so your first item would be myarray[0].

Just thought I would mention that before you trip over it.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:02 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2