很多站长朋友们都不太清楚php简单文章,今天小编就来给大家整理php简单文章,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 Thinkphp如何写简单的文章归档呢? 2、 有没有比较简单使用的PHP文章原代码 3、 简单分析PHP中序列化用法介绍 Thinkphp如何写简单的文章归档呢?发布文章的时候 把日期写进去,然后根据时间段统计文章个数,就行了
有没有比较简单使用的PHP文章原代码有一款比较不错。简单实用,功能也不少。还有搜索引擎蜘蛛爬行记录功能,免费的。
推荐一款给你用
阿西文章管理系统 好像这2天又有更新了新版本,我找了一下最新版的下载地址
真的不错,我也在用这个,而且他经常更新新的功能出来。还能自定义关键词、描述、还有频道功能。
简单分析PHP中序列化用法介绍简单分析PHP中序列化用法介绍
序列化在我们学习php中都会有用到了对于序列化我们常用的函数有serialize和unserialize了,希望以下这篇文章能够帮助到各位了解到PHP中序列化用法,具体如下:
0x00 序列化函数
serialize():返回带有变量类型和值的字符串
unserialize():想要将已序列化的字符串变回 PHP 的值
测试代码:
<?php
class test{
var $a;
var $b;
function __construct($a,$b,$c){
$a = $a;
$this->b = $b;
}
}
class test1 extends test{
function __construct($a){
$this->a = $a;
}
}
$a = 'hello';
$b = 123;
$c = false;
$d = new test('helloa','hellob','helloc');
$e = new test1('hello');
var_dump(serialize($a));
var_dump(serialize($b));
var_dump(serialize($c));
var_dump(serialize($d));
var_dump(serialize($e));
?>
运行结果:
string 's:5:"hello";' (length=12)
string 'i:123;' (length=6)
string 'b:0;' (length=4)
string 'O:4:"test":2:{s:1:"a";N;s:1:"b";s:6:"hellob";}' (length=46)
string 'O:5:"test1":2:{s:1:"a";s:5:"hello";s:1:"b";N;}' (length=46)
序列化字符串格式: 变量类型:变量长度:变量内容 。
如果序列化的是一个对象,序列化字符串格式为:
变量类型:类名长度:类名:属性数量:{属性类型:属性名长度:属性名;属性值类型:属性值长度:属性值内容}
将上述结果反序列化输出,执行结果:
string 'hello' (length=5)
int 123
boolean false
object(test)[1]
public 'a' => null
public 'b' => string 'hellob' (length=6)
object(test1)[1]
public 'a' => string 'hello' (length=5)
public 'b' => null
0x01 对象序列化
当序列化对象时,PHP 将在序列动作之前调用该对象的成员函数 sleep()。这样就允许对象在被序列化之前做任何清除操作。类似的,当使用 unserialize() 恢复对象时, 将调用 wakeup()成员函数。
在serialize()函数执行时,会先检查类中是否定义了 sleep()函数,如果存在,则首先调用 sleep()函数,如果不存在,就保留序列字符串中的所有属性。
在unserialize()函数执行时,会先检查是否定义了 wakeup()函数。如果 wakeup()存在,将执行__wakeup()函数,会使变量被重新赋值。
serialize()测试代码:
<?php
class test{
var $a;
var $b;
function __construct($a,$b,$c){
$this->a = $a;
$this->b = $b;
}
function __sleep(){
echo "b has changed"."\n";
$this->b = 'hib';
return $this->b;
}
function __wakeup(){
echo "a has changed"."\n";
$this->a = 'hia';
}
}
class test1 extends test{
function __construct($a){
$this->a = $a;
}
}
$d = new test('helloa','hellob','helloc');
$e = new test1('hello');
serialize($d);
serialize($e);
var_dump($d);
var_dump($e);
?>
执行结果:
b has changed b has changed
object(test)[1]
public 'a' => string 'helloa' (length=6)
public 'b' => string 'hib' (length=3)
object(test1)[2]
public 'a' => string 'hello' (length=5)
public 'b' => string 'hib' (length=3)
unserialize()测试代码:
class test{
var $a;
var $b;
function __construct($a,$b,$c){
$this->a = $a;
$this->b = $b;
}
function __sleep(){
echo "b has changed"."\n";
$this->b = 'hib';
return $this->b;
}
function __wakeup(){
echo "a has changed"."\n";
$this->a = 'hia';
}
}
class test1 extends test{
function __construct($a){
$this->a = $a;
}
}
$d = 'O:4:"test":2:{s:1:"a";N;s:1:"b";s:6:"hellob";}' ;
关于php简单文章的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。