Jump to content

How to parse a value into several variables


refiking

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.