如何解析wordpress分类法数据库内容

时间:2017-01-23 11:13:43

标签: php wordpress

这是wordpress数据库中postmeta表的行转储

如何在wordpress中解析这些数据。

a:17:{s:13:"pa_tea-coffee";a:6:{s:4:"name";s:13:"pa_tea-coffee";s:5:"value";s:0:"";s:8:"position";s:1:"0";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:24:"pa_bottled-mineral-water";a:6:{s:4:"name";s:24:"pa_bottled-mineral-water";s:5:"value";s:0:"";s:8:"position";s:1:"1";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:17:"pa_drinking-water";a:6:{s:4:"name";s:17:"pa_drinking-water";s:5:"value";s:0:"";s:8:"position";s:1:"2";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:8:"pa_wi-fi";a:6:{s:4:"name";s:8:"pa_wi-fi";s:5:"value";s:0:"";s:8:"position";s:1:"3";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:7:"pa_cctv";a:6:{s:4:"name";s:7:"pa_cctv";s:5:"value";s:0:"";s:8:"position";s:1:"4";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:20:"pa_security-services";a:6:{s:4:"name";s:20:"pa_security-services";s:5:"value";s:0:"";s:8:"position";s:1:"5";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:27:"pa_fire_fighting_equipmment";a:6:{s:4:"name";s:27:"pa_fire_fighting_equipmment";s:5:"value";s:0:"";s:8:"position";s:1:"6";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:25:"pa_fire-alarms-sprinklers";a:6:{s:4:"name";s:25:"pa_fire-alarms-sprinklers";s:5:"value";s:0:"";s:8:"position";s:1:"7";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:21:"pa_reception-services";a:6:{s:4:"name";s:21:"pa_reception-services";s:5:"value";s:0:"";s:8:"position";s:1:"8";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:24:"pa_housekeeping-services";a:6:{s:4:"name";s:24:"pa_housekeeping-services";s:5:"value";s:0:"";s:8:"position";s:1:"9";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:17:"pa_centralized-ac";a:6:{s:4:"name";s:17:"pa_centralized-ac";s:5:"value";s:0:"";s:8:"position";s:2:"10";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:23:"pa_multiple-powerpoints";a:6:{s:4:"name";s:23:"pa_multiple-powerpoints";s:5:"value";s:0:"";s:8:"position";s:2:"11";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:23:"pa_train-station-access";a:6:{s:4:"name";s:23:"pa_train-station-access";s:5:"value";s:0:"";s:8:"position";s:2:"12";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:14:"pa_ups-back-up";a:6:{s:4:"name";s:14:"pa_ups-back-up";s:5:"value";s:0:"";s:8:"position";s:2:"13";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:20:"pa_4-wheeler-parking";a:6:{s:4:"name";s:20:"pa_4-wheeler-parking";s:5:"value";s:0:"";s:8:"position";s:2:"14";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:20:"pa_2-wheeler-parking";a:6:{s:4:"name";s:20:"pa_2-wheeler-parking";s:5:"value";s:0:"";s:8:"position";s:2:"15";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:17:"pa_public-parking";a:6:{s:4:"name";s:17:"pa_public-parking";s:5:"value";s:0:"";s:8:"position";s:2:"16";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}}

1 个答案:

答案 0 :(得分:2)

将其保存到变量,而不是使用PHP的unserialze()函数

$test = 'a:17:{s:13:"pa_tea-coffee";a:6:{s:4:"name";s:13:"pa_tea-coffee";s:5:"value";s:0:"";s:8:"position";s:1:"0";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:24:"pa_bottled-mineral-water";a:6:{s:4:"name";s:24:"pa_bottled-mineral-water";s:5:"value";s:0:"";s:8:"position";s:1:"1";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:17:"pa_drinking-water";a:6:{s:4:"name";s:17:"pa_drinking-water";s:5:"value";s:0:"";s:8:"position";s:1:"2";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:8:"pa_wi-fi";a:6:{s:4:"name";s:8:"pa_wi-fi";s:5:"value";s:0:"";s:8:"position";s:1:"3";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:7:"pa_cctv";a:6:{s:4:"name";s:7:"pa_cctv";s:5:"value";s:0:"";s:8:"position";s:1:"4";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:20:"pa_security-services";a:6:{s:4:"name";s:20:"pa_security-services";s:5:"value";s:0:"";s:8:"position";s:1:"5";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:27:"pa_fire_fighting_equipmment";a:6:{s:4:"name";s:27:"pa_fire_fighting_equipmment";s:5:"value";s:0:"";s:8:"position";s:1:"6";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:25:"pa_fire-alarms-sprinklers";a:6:{s:4:"name";s:25:"pa_fire-alarms-sprinklers";s:5:"value";s:0:"";s:8:"position";s:1:"7";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:21:"pa_reception-services";a:6:{s:4:"name";s:21:"pa_reception-services";s:5:"value";s:0:"";s:8:"position";s:1:"8";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:24:"pa_housekeeping-services";a:6:{s:4:"name";s:24:"pa_housekeeping-services";s:5:"value";s:0:"";s:8:"position";s:1:"9";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:17:"pa_centralized-ac";a:6:{s:4:"name";s:17:"pa_centralized-ac";s:5:"value";s:0:"";s:8:"position";s:2:"10";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:23:"pa_multiple-powerpoints";a:6:{s:4:"name";s:23:"pa_multiple-powerpoints";s:5:"value";s:0:"";s:8:"position";s:2:"11";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:23:"pa_train-station-access";a:6:{s:4:"name";s:23:"pa_train-station-access";s:5:"value";s:0:"";s:8:"position";s:2:"12";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:14:"pa_ups-back-up";a:6:{s:4:"name";s:14:"pa_ups-back-up";s:5:"value";s:0:"";s:8:"position";s:2:"13";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:20:"pa_4-wheeler-parking";a:6:{s:4:"name";s:20:"pa_4-wheeler-parking";s:5:"value";s:0:"";s:8:"position";s:2:"14";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:20:"pa_2-wheeler-parking";a:6:{s:4:"name";s:20:"pa_2-wheeler-parking";s:5:"value";s:0:"";s:8:"position";s:2:"15";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:17:"pa_public-parking";a:6:{s:4:"name";s:17:"pa_public-parking";s:5:"value";s:0:"";s:8:"position";s:2:"16";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}}';
$result = unserialize($test);
print_r($result);