I have a table inside wordpress which is wp_usermeta
with the meta_key
filed and a value called wp_s2member_custom_fields
which holds a bunch of concatenated values like below.
我在wordpress中有一个表,它是带有meta_key字段的wp_usermeta和一个名为wp_s2member_custom_fields的值,它包含一堆连接值,如下所示。
How can I extract the data next to monthly_uniques
inside this value?
如何在此值内提取monthly_uniques旁边的数据?
a:12:{
s:7:"country";
s:2:"CA";
s:4:"city";
s:8:"Brampton";
s:5:"state";
s:7:"Ontario";
s:8:"zip_code";
s:6:"L6T4E7";
s:3:"age";
s:13:"25–34 years";
s:8:"blog_url";
s:22:"http://www.blog.com";
s:16:"blog_description";
s:106:"A blog about blogging";
s:15:"monthly_uniques";
s:4:"1000";
s:13:"facebook_page";
s:55:"http://www.facebook.com/myfacebookpage";
s:14:"facebook_likes";
s:3:"128";
s:15:"twitter_account";
s:31:"http://twitter.com/mytwitterpage";
s:17:"twitter_followers";
s:3:"392";}
In actual fact al these values are on one line, put them on separate lines for clarity
实际上,这些值在一条线上,为了清楚起见,将它们放在单独的线上
I need to pull this data in different ways to show reports. What do I add the below statement to pull montly_uniques
, city, zip_code, etc?
我需要以不同的方式提取这些数据来显示报告。我如何添加以下语句来拉取montly_uniques,city,zip_code等?
1 个解决方案
#1
2
When Wordpress enters an array into its database, it does something called Serializing, where it turns an array into the format of the string you supplied. To reverse this process and get back the same array, you simply need to run that string above through PHP's built-in unserialize() function, which will return an associative array in the manner you mentioned above.
当Wordpress将一个数组输入其数据库时,它会执行一个名为Serializing的操作,它将数组转换为您提供的字符串格式。要反转此过程并返回相同的数组,您只需要通过PHP的内置unserialize()函数运行上面的字符串,该函数将以您上面提到的方式返回一个关联数组。
So something like this:
所以这样的事情:
$string = 'a:12:{s:7:"country";s:2:"CA";s:4:"city";s:8:"Brampton";s:5:"state";s:7:"Ontario";s:8:"zip_code";s:6:"L6T4E7";s:3:"age";s:13:"25–34 years";s:8:"blog_url";s:22:"http://www.blog.com";s:16:"blog_description";s:106:"A blog about blogging";s:15:"monthly_uniques";s:4:"1000";s:13:"facebook_page";s:55:"http://www.facebook.com/myfacebookpage";s:14:"facebook_likes";s:3:"128";s:15:"twitter_account";s:31:"http://twitter.com/mytwitterpage";s:17:"twitter_followers";s:3:"392";}';
$array = unserialize($string);
$array['monthly_uniques']; //This will give you the monthly_uniques field.
#1
2
When Wordpress enters an array into its database, it does something called Serializing, where it turns an array into the format of the string you supplied. To reverse this process and get back the same array, you simply need to run that string above through PHP's built-in unserialize() function, which will return an associative array in the manner you mentioned above.
当Wordpress将一个数组输入其数据库时,它会执行一个名为Serializing的操作,它将数组转换为您提供的字符串格式。要反转此过程并返回相同的数组,您只需要通过PHP的内置unserialize()函数运行上面的字符串,该函数将以您上面提到的方式返回一个关联数组。
So something like this:
所以这样的事情:
$string = 'a:12:{s:7:"country";s:2:"CA";s:4:"city";s:8:"Brampton";s:5:"state";s:7:"Ontario";s:8:"zip_code";s:6:"L6T4E7";s:3:"age";s:13:"25–34 years";s:8:"blog_url";s:22:"http://www.blog.com";s:16:"blog_description";s:106:"A blog about blogging";s:15:"monthly_uniques";s:4:"1000";s:13:"facebook_page";s:55:"http://www.facebook.com/myfacebookpage";s:14:"facebook_likes";s:3:"128";s:15:"twitter_account";s:31:"http://twitter.com/mytwitterpage";s:17:"twitter_followers";s:3:"392";}';
$array = unserialize($string);
$array['monthly_uniques']; //This will give you the monthly_uniques field.