Jump to content

Recommended Posts

Hi

 

I have this entry in a database from wpforms

a:5:{s:16:"WPFormsDB_status";s:6:"unread";s:4:"Name";s:13:"Lional Hewitt";s:14:"Contact Number";s:10:"0763229844";s:5:"Email";s:22:"[email protected]";s:18:"Comment or Message";s:5:"test2";}

From this I want to extract Lional Hewitt, 0763229844, [email protected], and test2 into separate variables. I see each form is referenced by s:13, s:10, s:22, and s:18. Is there someway to splat the string with those values

Thank you

 

Link to comment
https://forums.phpfreaks.com/topic/326441-extracting-info-from-database-using-php/
Share on other sites

You need to unserialise the data.

$dbdata = 'a:5:{s:16:"WPFormsDB_status";s:6:"unread";s:4:"Name";s:13:"Lional Hewitt";s:14:"Contact Number";s:10:"0763229844";s:5:"Email";s:22:"[email protected]";s:18:"Comment or Message";s:5:"test2";}';
$data = unserialize($dbdata);

    echo "Name : {$data['Name']}<br>";
    echo "Contact : {$data['Contact Number']}<br>";
    // etc

Alternatively

$dbdata = 'a:5:{s:16:"WPFormsDB_status";s:6:"unread";s:4:"Name";s:13:"Lional Hewitt";s:14:"Contact Number";s:10:"0763229844";s:5:"Email";s:22:"[email protected]";s:18:"Comment or Message";s:5:"test2";}';
$data = unserialize($dbdata);

foreach ($data as $key => $value)   {
    echo "<b>$key</b> : $value<br>";
}

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.