使用分隔符分隔多个部分

时间:2016-05-23 17:34:08

标签: php

我有这个数据我想提取年份:2012年,地点:享有盛誉的业务,清洁:PHP中的日常办公室清洁服务;

a:8:{s:10:"Year Built";s:4:"2012";s:8:"Location";s:28:"Prestigious business address";s:8:"Cleaning";s:30:"Daily Office Cleaning Services";s:11:"Maintenance";s:29:"Common Area Maintenance (CAM)";s:9:"Utilities";s:49:"Air conditioning, electricity and water utilities";s:9:"Furniture";s:17:"Already Installed";s:6:"Access";s:27:"24/7 365 Access To Building";s:10:"Lobby Area";s:21:"Friendly Receptionist";}

到目前为止,我已经能够提取除s:4:a:8:{s:10:之外的所有内容

2 个答案:

答案 0 :(得分:1)

非常简单,它是序列化的。只需unserialize()并访问数组:

$result = unserialize($data);
echo $result['Year Built'];  // 2012

执行print_r($result);收益:

(
    [Year Built] => 2012
    [Location] => Prestigious business address
    [Cleaning] => Daily Office Cleaning Services
    [Maintenance] => Common Area Maintenance (CAM)
    [Utilities] => Air conditioning, electricity and water utilities
    [Furniture] => Already Installed
    [Access] => 24/7 365 Access To Building
    [Lobby Area] => Friendly Receptionist
)

答案 1 :(得分:0)

这是serialize只需使用unserialize,即可获得数组。

$arr = unserialize("");
print_r($arr );

echo $arr['Year Built']; //2012
echo $arr['Location']; //Prestigious business address

现在您可以访问此数组,您将获得值:

Array
(
    [Year Built] => 2012
    [Location] => Prestigious business address
    [Cleaning] => Daily Office Cleaning Services
    [Maintenance] => Common Area Maintenance (CAM)
    [Utilities] => Air conditioning, electricity and water utilities
    [Furniture] => Already Installed
    [Access] => 24/7 365 Access To Building
    [Lobby Area] => Friendly Receptionist
)