lional Posted January 6 Share Posted January 6 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 Quote Link to comment https://forums.phpfreaks.com/topic/326441-extracting-info-from-database-using-php/ Share on other sites More sharing options...
Barand Posted January 6 Share Posted January 6 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>"; } Quote Link to comment https://forums.phpfreaks.com/topic/326441-extracting-info-from-database-using-php/#findComment-1647660 Share on other sites More sharing options...
lional Posted January 7 Author Share Posted January 7 Thank you much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/326441-extracting-info-from-database-using-php/#findComment-1647674 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.