refiking Posted January 17, 2012 Share Posted January 17, 2012 I am trying to take a value that is stored in a db for address and parse it into 4 different variables: $address $city $state $zip when I started the loop and echo'd the results, here is how it comes out: a:4:{s:14:"street_address";s:20:"811 East Parrish Ave";s:4:"city";s:9:"Owensboro";s:5:"state";s:2:"KY";s:3:"zip";s:5:"42303";} a:4:{s:14:"street_address";b:0;s:4:"city";b:0;s:5:"state";b:0;s:3:"zip";b:0;} a:4:{s:14:"street_address";s:15:"800 Rose Street";s:4:"city";s:9:"Lexington";s:5:"state";s:2:"KY";s:3:"zip";s:5:"40536";} a:4:{s:14:"street_address";s:19:"1300 State Hwy 3298";s:4:"city";s:10:"Olive Hill";s:5:"state";s:2:"KY";s:3:"zip";s:5:"41164";} a:4:{s:14:"street_address";s:22:"1301 North Race Street";s:4:"city";s:7:"Glasgow";s:5:"state";s:2:"KY";s:3:"zip";s:5:"42141";} a:4:{s:14:"street_address";s:23:"200 Abraham Flexner Way";s:4:"city";s:10:"Louisville";s:5:"state";s:2:"KY";s:3:"zip";s:5:"40202";} Link to comment https://forums.phpfreaks.com/topic/255246-how-to-parse-a-value-into-several-variables/ Share on other sites More sharing options...
Psycho Posted January 17, 2012 Share Posted January 17, 2012 That data is a serialized array. Simply unserialize() each record and you will have an array that you can access each piece of data independently. while($row = mysql_fetch_assoc($result)) { $data = unserialize($row['field_name']); echo "Street: {$data['street_address']}<br>\n"; echo "City: {$data['city']}<br>\n"; echo "State: {$data['state']}<br>\n"; echo "ZIP: {$data['zip']}<br>\n"; } Link to comment https://forums.phpfreaks.com/topic/255246-how-to-parse-a-value-into-several-variables/#findComment-1308691 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.