Split an array on a delimiter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mcmcom
Forum Newbie
Posts: 14
Joined: Thu Jan 31, 2008 7:23 am

Split an array on a delimiter

Post by mcmcom »

hi all,
new to php - old to programming.
i need to split a delimited string of values. i tried split but it split each character in the string into its own value in an array.

i need somethign like this:
"spaghetti, ice cream, borat"
in an array like
arr[0]spaghetti
arr[1]ice cream
arr[2]borat

how can i perform this ?

thanks,
mcm
User avatar
webspider
Forum Commoner
Posts: 52
Joined: Sat Oct 27, 2007 3:29 am

Re: Split an array on a delimiter

Post by webspider »

Code: Select all

 
$str = "spaghetti, ice cream, borat";
$arr = explode(",", $str);
 
Post Reply