0

我想知道如何从 MySQL 数据库中的任何特定行单元格中提取详细信息。这些详细信息位于 MySQL 表的一个单元格中。具体来说,我想提取

cwall_id which is photos1187       
uri    which is photos/viewstory/1187
name     which is nmart
thumb which is uploads/userfiles/201205/13_03_pceb9.jpg

我有这个:

a:1:{i:0;s:275:"a:4:{s:8:"cwall_id";s:10:"photos1187";s:3:"uri";s:21:"photos/viewstory/1187";s:4:"name";s:5:"nmart";s:5:"thumb";a:3:{i:0;s:40:"uploads/userfiles/201205/13_03_pceb9.jpg";i:1;s:40:"uploads/userfiles/201205/13_03_0wlih.jpg";i:2;s:40:"uploads/userfiles/201205/13_03_tq5wf.jpg";}}";}
4

1 回答 1

2

如果我理解正确,此单元格信息已使用序列化http://php.net/manual/en/function.serialize.php保存

您需要先unserialize http://www.php.net/manual/en/function.unserialize.php它才能提取您需要的信息..

例子

$cell = 'a:1:{i:0;s:275:"a:4:{s:8:"cwall_id";s:10:"photos1187";s:3:"uri";s:21:"photos/viewstory/1187";s:4:"name";s:5:"nmart";s:5:"thumb";a:3:{i:0;s:40:"uploads/userfiles/201205/13_03_pceb9.jpg";i:1;s:40:"uploads/userfiles/201205/13_03_0wlih.jpg";i:2;s:40:"uploads/userfiles/201205/13_03_tq5wf.jpg";}}";}';
$list = unserialize($cell);
$info = unserialize($list[0]);
var_dump($info);

输出

array
  'cwall_id' => string 'photos1187' (length=10)
  'uri' => string 'photos/viewstory/1187' (length=21)
  'name' => string 'nmart' (length=5)
  'thumb' => 
    array
      0 => string 'uploads/userfiles/201205/13_03_pceb9.jpg' (length=40)
      1 => string 'uploads/userfiles/201205/13_03_0wlih.jpg' (length=40)
      2 => string 'uploads/userfiles/201205/13_03_tq5wf.jpg' (length=40)

你想要的信息

echo $info['cwall_id'] ;
echo $info['uri'] ;
echo $info['thumb'][1] ;
于 2012-05-12T18:58:37.367 回答