2009-10-24 95 views
0
132 
a:4:{s:8:"template";a:1:{s:10:"index.html";b:1;}s:9:"timestamp";i:1256373019;s:7:"expires";i:1256373079;s:13:"cache_serials";a:0:{}}<body> 
php<br > 
    java<br > 
    c++<br > 

</body> 

有人能解释这一部分:smarty缓存文件的头是什么意思?

132 
    a:4:{s:8:"template";a:1:{s:10:"index.html";b:1;}s:9:"timestamp";i:1256373019;s:7:"expires";i:1256373079;s:13:"cache_serials";a:0:{}} 
+1

你需要知道的Smarty的缓存文件的内部工作? – cletus 2009-10-24 08:36:37

+0

@cletus,是的,我做到了! – Mask 2009-10-24 08:51:09

回答

1

这是一个PHP数组的序列化版本:

<?php 
$serialized = 'a:4:{s:8:"template";a:1:{s:10:"index.html";b:1;}s:9:"timestamp";i:1256373019;s:7:"expires";i:1256373079;s:13:"cache_serials";a:0:{}}'; 
$unserialized = unserialize($serialized); 
print_r($unserialized); 

结果:

Array 
(
[template] => Array 
    (
     [index.html] => 1 
    ) 

[timestamp] => 1256373019 
[expires] => 1256373079 
[cache_serials] => Array 
    (
    ) 

) 
1

我不知道很多关于Smarty的,但看起来像类似于Bencoding东西,这是你编码之类的字符串和数组通过指定它们的长度第一。这避免了必须使用“特殊字符”(例如引号)来区分这些事情,如果它们出现在实际字符串中,那么它们需要被“转义”。

  • 132是编码字符串的长度。
  • a:4:看起来像是引入了一个包含4个项目的关联数组(字典)。
  • s:8:"template"似乎是长度为8的字符串,值为“template”。在这种情况下,它是字典中第一项的关键。
  • 在这种情况下,该项目的值是仅将密钥“index.html”映射到整数值1的另一个字典。
  • ...我想你可以解决其余问题。