PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Oct 24, 2017 2:51 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Oct 10, 2017 5:54 am 
Offline
Forum Contributor

Joined: Tue Jul 28, 2009 9:26 am
Posts: 184
Hello,

I have a string from my database table I want to turn into an array and get part of it. the string is as below

Syntax: [ Download ] [ Hide ]

$FromTable = '

a:11:{s:7:"form_id";s:4:"4821";s:9:"timestamp";s:10:"1501333433";s:7:"request";s:0:"";s:4:"role";s:6:"member";s:8:"_wpnonce";s:10:"23395536bf";s:16:"_wp_http_referer";s:10:"/register/";s:10:"user_login";s:11:"iCTTraining";s:10:"first_name";s:4:"Egbu";s:9:"last_name";s:0:"";s:10:"user_email";s:25:"Linksnetsystems@yahoo.com";s:5:"sr_id";s:7:"CALA038";}

'

//from the string, how do I get the value as follow
form_id = 4821
timestamp = 1501333433
......
user_email = Linksnetsystems@yahoo.com
sr_id = CALA038

//also if i need only the the value of user_email
 


how do i do it?

Thanks


Top
 Profile  
 
PostPosted: Tue Oct 10, 2017 6:16 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6391
Location: Montreal, Canada
Looks like a serialized array. Try calling unserialize on it.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Tue Oct 10, 2017 3:25 pm 
Offline
Forum Contributor

Joined: Tue Jul 28, 2009 9:26 am
Posts: 184
Thanks Celauran,

I was able to figure it out as below

Syntax: [ Download ] [ Hide ]

$FromTable = 'a:11:{s:7:"form_id";s:4:"4821";s:9:"timestamp";s:10:"1501333433";s:7:"request";s:0:"";s:4:"role";s:6:"member";s:8:"_wpnonce";s:10:"23395536bf";s:16:"_wp_http_referer";s:10:"/register/";s:10:"user_login";s:11:"iCTTraining";s:10:"first_name";s:4:"Egbu";s:9:"last_name";s:0:"";s:10:"user_email";s:25:"Linksnetsystems@yahoo.com";s:5:"sr_id";s:7:"CALA038";}';

// Unserialize the data  
//https://www.w3resource.com/php/function-reference/unserialize.php
$var1 = unserialize($FromTable);  
//var_dump ($var1);


//https://stackoverflow.com/questions/2281526/php-how-to-get-value-from-array-if-key-is-in-a-variable
//echo "<pre>" , print_r($var1, 1) , "</pre>";
$sr_id = $var1['sr_id'];
$email = $var1['user_email'];
print "ID: ".$sr_id."<br/>";
print "Email: ".$email;

 


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group