[WordPress] php の wp で配列をアンシリアライズする方法?

スポンサーリンク

質問

get_post_meta($post_id,'meta_key_here',true);

としている値を: 私は meta_key が含まれているデータベースに

a:3:{i:0;a:4:{s:5:"title";s:10:"Directions";s:2:"id";s:14:"tab-directions";s:7:"content";s:422:"<strong>Custom fields </strong> can be used to add extra metadata to a post that you can use in your theme.
 <ul>
  <li>Custom fields can be used to add extra metadata to a post that you can use in your theme.</li>
 <li>Custom fields can be used to add extra metadata to a post that you can use in your theme.</li>
 <li>Custom fields can be used to add extra metadata to a post that you can use in your theme.</li>

</ul>";s:15:"tooltip_content";s:13:"tooltip dataa";}i:1;a:4:{s:5:"title";s:18:"Directions for use";s:2:"id";s:22:"tab-directions-for-use";s:7:"content";s:736:"<strong>Custom fields </strong> can be used to add extra metadata to a post that you can use in your theme.
 <ul>
 <li>Custom fields can be used to add extra metadata to a post that you can use in your theme.</li>
 <li>Custom fields can be used to add extra metadata to a post that you can use in your theme.</li>
  <a href=""><strong>Custom fields </strong> can be used to add extra metadata to a post that you can use in your theme.
 <ul>
  <li>Custom fields can be used to add extra metadata to a post that you can use in your theme.</li>
   <li>Custom fields can be used to add extra metadata to a post that you can use in your theme.</li>
  Custom fields can be used to add extra metadata to a post that you can use in your theme. </a>";s:15:"tooltip_content";s:15:"tooltip dataa 2";}i:2;a:4:{s:5:"title";s:25:"super charged ingredients";s:2:"id";s:29:"tab-super-charged-ingredients";s:7:"content";s:413:"<strong>Custom fields </strong> can be used to add extra metadata to a post that you can use in your theme.
<ul>
 <li>Custom fields can be used to add extra metadata to a post that you can use in your theme.</li>
 <li>Custom fields can be used to add extra metadata to a post that you can use in your theme.</li>
 <li>Custom fields can be used to add extra metadata to a post that you can use in your theme.</li>";s:15:"tooltip_content";s:15:"tooltip dataa 3";}}

これを試みるとき

`$my_data=unserialize($data); 
 print_r($my_data);` 

それ何も表示されません (。空の配列)。(このシリアル化された配列から特定の投稿 id に対して tooltip_content を取得するしたい)

答え

値が無効です。

false

を取得しますそれをアンシリアライズする場合と通知:

Notice: unserialize(): Error at offset 518 of 2043 bytes

print_r(false)

は、何も印刷されません、

var_dump

を使用してより正確なデバッグ用

http://stackoverflow.com/questions/28941143/how-to-unserialize-array-in-php-wp

スポンサーリンク

Leave a Reply