Home > php教程 > php手册 > body text

【PHP】php中serialize和unserialize的使用

WBOY
Release: 2016-06-06 19:44:58
Original
2148 people have browsed it

首先创建demo.php ?php header(Content-Type:text/html;Charset=utf-8);$files[]=1; $files[3]='hahaha'; $files[7]='测试'; $files['username']='aaa'; $files['userid']=899; $files['truename']=真实name; print_r($files); print_r(hr/); print_r(serial

首先创建demo.php


header("Content-Type:text/html;Charset=utf-8");$files[]=1;
$files[3]='hahaha';
$files[7]='测试';
$files['username']='aaa';
$files['userid']=899;
$files['truename']="真实name";
print_r($files);
print_r("


");
print_r(serialize($files));
print_r("
");

$file2=array();
$file2='a:3:{s:2:"id";i:2;s:8:"username";s:3:"kkk";i:1;i:334;}';
print_r(unserialize($file2));

?>


输出内容如下:

Array ( [0] => 1 [3] => hahaha [7] => 测试 [username] => aaa [userid] => 899 [truename] => 真实name )


a:6:{i:0;i:1;i:3;s:6:"hahaha";i:7;s:6:"测试";s:8:"username";s:3:"aaa";s:6:"userid";i:899;s:8:"truename";s:10:"真实name";}

Array ( [id] => 2 [username] => kkk [1] => 334 )


如果想post传递$files的内容,可能有些困难,因为有双引号

如 $files = a:2:{i:11;s:3:"111";i:22;s:3:"222";}

那就先要unserialize($files)形成数组形式,再foreach循环

                  foreach($files as $file):?>
                      ">
                  endforeach;?>

这样就可以post表单达到想要的内容了。

Array ( [11] => 111 [22] => 222 )

以上仅是一种方法,也可能是最麻烦的,欢迎指正




Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template