-1

这让我困惑了一天,所以我需要一些帮助。在给定的字符串中,例如以下:

$str = 'a:1:{s:8:"post_tag";a:5:{
i:460;a:5:{s:11:"wpseo_title";s:8:"demodemo";s:10:"wpseo_desc";s:8:"demodemo";s:13:"wpseo_bctitle";s:8:"demodemo";s:13:"wpseo_noindex";s:7:"default";s:21:"wpseo_sitemap_include";s:1:"-";}
i:459;a:5:{s:11:"wpseo_title";s:8:"testtest";s:10:"wpseo_desc";s:8:"testtest";s:13:"wpseo_bctitle";s:8:"testtest";s:13:"wpseo_noindex";s:7:"default";s:21:"wpseo_sitemap_include";s:1:"-";}
i:462;a:5:{s:11:"wpseo_title";s:7:"bikey77";s:10:"wpseo_desc";s:7:"bikey77";s:13:"wpseo_bctitle";s:7:"bikey77";s:13:"wpseo_noindex";s:7:"default";s:21:"wpseo_sitemap_include";s:1:"-";}
i:463;a:5:{s:11:"wpseo_title";s:7:"dimitra";s:10:"wpseo_desc";s:7:"dimitra";s:13:"wpseo_bctitle";s:7:"dimitra";s:13:"wpseo_noindex";s:7:"default";s:21:"wpseo_sitemap_include";s:1:"-";}
i:464;a:5:{s:11:"wpseo_title";s:8:"dimitra1";s:10:"wpseo_desc";s:8:"dimitra1";s:13:"wpseo_bctitle";s:8:"dimitra1";s:13:"wpseo_noindex";s:7:"default";s:21:"wpseo_sitemap_include";s:1:"-";}
}}';

如何计算以 i:XXX... 开头并以 ...;} 结尾的子字符串的数量?

子字符串示例:

i:460;a:5:s:11:"wpseo_title";s:8:"demodemo";s:10:"wpseo_desc";s:8:"demodemo";s:13:"wpseo_bctitle";s:8:"demodemo";s:13:"wpseo_noindex";s:7:"default";s:21:"wpseo_sitemap_include";s:1:"-";}

4

2 回答 2

0

这是序列化数据,反序列化它

$arr = unserialize($str);
echo count($arr['post_tag']);
于 2013-04-19T07:10:27.650 回答
0

看起来你正在处理一个序列化数组,所以......

$data = unserialize($str);
echo count($data['post_tag']);
于 2013-04-19T07:09:45.230 回答