drjmrg8766
drjmrg8766
2013-04-25 20:34

从值中获取数组中的特定MySQL数据?

已采纳

I want to get a specific value out of a MySql database.

I have:

SELECT option_value 
FROM wp_options 
WHERE option_name = 'DevloungePluginSeriesAdminOptions'

Which outputs:

a:4:{s:11:"add_content";s:4:"true";s:7:"content";s:45:"155000009-9a5sg2t42q2k0159ko8hkdo85hjlu69j";s:11:"show_header";s:4:"true";s:14:"comment_author";s:4:"true";}

I think this is some sort of array. I don't know how handle it. I only want the 155000009-9a5sg2t42q2k0159ko8hkdo85hjlu69j part of the string.

How can I get just 155000009-9a5sg2t42q2k0159ko8hkdo85hjlu69j?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • duanbi8089 duanbi8089 8年前

    This data is in serialized format. You need to unserialize it before extracting the array value.

    Suppose result object is $result, then following code will work:

    $option_value = unserialize( $result->option_value );
    $output = $option_value['content'];
    
    点赞 评论 复制链接分享
  • douju5062 douju5062 8年前

    put the value in a variable and unserialize:

    $val = unserialize( $val );
    

    You'll get a PHP array as a result, inspect it with

    print_r( $val );
    
    点赞 评论 复制链接分享

相关推荐