Re: Breaking Up a String

From: Date: Sun, 17 Dec 2000 21:26:36 +0000
Subject: Re: Breaking Up a String
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-30771@lists.php.net to get a copy of this message
Or, this.... $row_ar = split("\",\"", $row); list ($name, $date, $zip, $city, $state) = $row_ar; You get the idea ;) Toby Butzon [ criticism spurs improvement ] ----- Original Message ----- From: "Joe Stump" <joe@earth.care2.com> To: "Jason Beebe" <jbeebe@op480.com> Cc: <php-general@lists.php.net> Sent: Sunday, December 17, 2000 4:24 PM Subject: Re: [PHP] Breaking Up a String : Sure: : : <? : : $line = '"Joe Schmoe","10/00","2345","California"'; : $fields = explode(',',$line); : for($i = 0 ; $i < sizeof($fields) ; ++$i) : { : $new_fields[$i] = str_replace('"','',$fields[$i]; : } : : $name = $new_fields[0]; : $date = $new_fields[1]; : : // etc, etc. : : ?> : : --Joe : : : : On Sun, Dec 17, 2000 at 02:26:14PM -0700, Jason Beebe wrote: : > Hey, : > : > Anyone have an efficient way of doing this. : > Say I have a string deliminated and seperated by quotes and comas like this: : > "Joe Shmoe","10/00","2342","California" etc... there's about 8 fields of information. : > How could I seperate each one into a seperate variable. I was thinking that putting the seperated data into an array may work and sort it from there. : > $name = $separray[0]; : > $date = $separray[1]; : > : > It always returns the fields in the same order, so that is not a problem. How would I seperate this information to begin with. Then, what would be the best method of assigning the seperated data into it's own unique variable? Thanks. : : --- : Joe Stump : PHP Programmer : www.Care2.com : : : -- : PHP General Mailing List (http://www.php.net/) : To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net : For additional commands, e-mail: php-general-help@lists.php.net : To contact the list administrators, e-mail: php-list-admin@lists.php.net : :

« previous php.general (#30771) next »