没有合适的资源?快使用搜索试试~ 我知道了~
php 序列化和反序列化学习-1
需积分: 0 0 下载量 92 浏览量
2022-08-03
15:36:07
上传
评论
收藏 519KB PDF 举报
温馨提示
试读
12页
2020/6/21 下午9(37php 序列化和反序列化学习 · 语雀第 1 页(共 12 页)3 R - pointer reference U - unic
资源详情
资源评论
资源推荐
2020/6/21 下午9(37php 序化和反序化学习 · 语雀
第 1 (共 12 )https://www.yuque.com/zhuifengshaonian-cwb42/pg4cor/sen94k
1 a - array b - boolean d - double i - integer o - common object
2 r - reference s - string C - custom object O - class N - null
3 R - pointer reference U - unicode string
1 NULL --> N;
2 boolean --> b:x; x->(0,1)
3 integer --> i:x; x->(-2147483648,2147483647)
4 double --> d:x;
5 string --> s:l:x; l,x->(length,string)
6 arrary --> a:l:{<k1><v1><k2><v2>...} l,k,v->(length,key,value)
7 object --> O:l1:n:l2:{<name><value>..} n->(obj.name)
1 <?php
2 class Test
3 {
4 var $a = 1;
5 public $b = 2;
6 protected $c = 'hello';
7 private $d = 'world';
8
9 function __construct()
10 {
11 # code...
2020/6/21 下午9(37php 序化和反序化学习 · 语雀
第 2 (共 12 )https://www.yuque.com/zhuifengshaonian-cwb42/pg4cor/sen94k
12 }
13 function __destruct()
14 {
15 # code...
16 }
17 }
18 $obj = new Test();
19 echo serialize($obj);
20 ?>
1 $array = array('x' =>'hello','y' =>'world' );
2 var_dump($array);
3 echo serialize($array);
4 +------------result-------------+
5 array(2) {
6 ["x"]=>
7 string(5) "hello"
8 ["y"]=>
9 string(5) "world"
10 }
11 a:2:{s:1:"x";s:5:"hello";s:1:"y";s:5:"world";}
1 $result = 'a:2:{s:1:"x";s:7:"hello";s:1:"y";s:5:"world";}';
2 var_dump(unserialize($result));
3 +------------result-------------+
4 PHP Notice: unserialize(): Error at offset 45 of 46 bytes in /test.php on line 1
5 bool(false)
1 $result = 'a:2:{s:1:"x";s:5:"hello";s:1:"y";s:5:"world";}";s:1:"y";s:5:"ooooo";}';
2 var_dump(unserialize($result));
2020/6/21 下午9(37php 序化和反序化学习 · 语雀
第 3 (共 12 )https://www.yuque.com/zhuifengshaonian-cwb42/pg4cor/sen94k
2 var_dump(unserialize($result));
3 +------------result-------------+
4 array(2) {
5 ["x"]=>
6 string(5) "hello"
7 ["y"]=>
8 string(5) "world"
9 }
1 $result = 'a:2:{s:1:"x";s:28:"hello";s:1:"y";s:5:"world";}";s:1:"y";s:5:"ooooo";}';
2 var_dump(unserialize($result));
3 +------------result-------------+
4 array(2) {
5 ["x"]=>
6 string(28) "hello";s:1:"y";s:5:"world";}"
7 ["y"]=>
8 string(5) "ooooo"
9 }
1 <?php
2 #$name = $_GET['name'];
3 $name = 'boy';
4 $test = "how are you";
5 $user = array('name' => $name,'test' => $test);
6
7 $seri_strings = filter(serialize($user));
8 echo $seri_strings;
9
10 function filter($strings){
11 return preg_replace('/x/','**', $strings);
12 }
13 ?>
14 +------------result-------------+
15 name = boy -> a:2:{s:4:"name";s:3:"boy";s:4:"test";s:11:"how are you";}
16 name = boyx -> a:2:{s:4:"name";s:4:"boy**";s:4:"test";s:11:"how are you";}
剩余11页未读,继续阅读
泡泡SOHO
- 粉丝: 22
- 资源: 294
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0