本文主要讲解php类cfpropertylist来实现plist文件的读、写、修改,plist介绍和php library cfpropertylist的介绍。 plist介绍 plist的全称是property lists,是一种用来存储串行化后的对象的文件。属性列表文件的文件扩展名为 .plist ,因此通常被称为 plist
本文主要讲解php类cfpropertylist来实现plist文件的读、写、修改,plist介绍和php library cfpropertylist的介绍。
plist介绍plist的全称是property lists,是一种用来存储串行化后的对象的文件。属性列表文件的文件扩展名为.plist,因此通常被称为plist文件。plist文件通常用于储存用户设置,也可以用于存储捆绑的信息。
plist组织数据到命名值和列表值,主要通过几个主要的core foundation类型:cfstring, cfnumber, cfboolean, cfdate, cfdata, cfarray, 和 cfdictionary。
plist结构和内容
property lists从基本的core foundation 类型:cfstring,cfnumber,cfboolean,cfdate,cfdata构造。要建立一个复杂的数据结构从这些基本类型,你得把它们放在里面cfdictionary或cfarray里面。为了简化对property lists的编程,任何属性列表类型也可以被引用通过使用类型cfpropertylistref。
在一个cfdictionary,数据结构是以键-值对的形式,其中每个键是一个字符串,该键的值可以是一个cfstring字符串,一个cfnumber,一个cfboolean,一个cfdate,一个cfdata,一个cfarray,或其他cfdictionary。当使用cfdictionary作为属性列表时,所有的键必须是字符串。
在一个cfarray,数据结构是以一个可以通过索引访问的对象的有序集合。在属性列表中,一个cfarray可以包含任何的基本属性列表类型,以及cfdictionary和其他cfarray的对象。
property list xml 标签
当属性列表将core foundation对象集合转换成一个xml的属性列表,使用文件类型标签来包含所有的属性列表。下表中列出core foundation数据类型常用的其他标记:
core foundation数据类型等同的xml
core foundation类型
xml标签
cfstring
cfnumber
或者
cfboolean
或者
cfdate
cfdata
cfarray
cfdictionary
php类cfpropertylist通过php来实现苹果property list,php类cfpropertylist不仅可以处理xml propertylists,而且也可以处理二进制property lists。它提供的功能可以轻松地转换数据到php中,例如重新计算时间戳从unix纪元到苹果纪元,反之亦然。它有一个重大的功能就是从一个正常的php数据结构自动地创建为property list数据结构,它将帮助你输出你的数据到plist中在任何时候。
运行环境
cfpropertylist不依赖任何“苹果专有的”组件像plutil。 cfpropertylist运行在任何具有php的操作系统和一些标准php扩展。
虽然您可能希望将数据传送到你的iphone应用程序,你可能想运行这些服务器端的服务在标准的linux(甚至windows)环境作为一种服务,而不是购买昂贵的苹果服务器上。随着cfpropertylist的发展,你现在有能力提供数据从您最喜爱的操作系统。
要求和限制
需要php5.3(为cfpropertylist2.0)需要mbstring或iconv php扩展类库列表及功能
cfpropertylist.php,cfpropertylist核心处理,包括读、写、修改和保存propertylist。cfbinarypropertylist.php,读写二进制格式的property lists的工具。从苹果cfbinaryplist.c移植而来。cftype.php,cfpropertylist所使用的所有cftypes的基础类。cftypedetector.php,转换本地php的数据结构到cfpropertylist对象的接口。ioexception.php,基本输入/ 输出异常。plistexception.php,plist格式的异常错误。php类cfpropertylist 使用方法从plist文件中读取数据到php数组
toarray());
echo ‘
’;
var_dump( $plist->toarray() );
echo ‘
’;
?>通过cfpropertylist plist api将php数据写入到plist文件
add( $dict = new cfdictionary() );
// year of birth1965
$dict->add( ‘year of birth’, new cfnumber( 1965 ) );
// date of graduation2004-06-22t19:23:43z
$dict->add( ‘date of graduation’, new cfdate( gmmktime( 19, 23, 43, 06, 22, 2004 ) ) );
// pets names
$dict->add( ‘pets names’, new cfarray() );
// picturepekbpyglmyfcpa==
// 为了保持简单,我们插入一个已经base64编码的字符串
$dict->add( ‘picture’, new cfdata( ‘pekbpyglmyfcpa==’, true ) );
// city of birthspringfield
$dict->add( ‘city of birth’, new cfstring( ‘springfield’ ) );
// namejohn doe
$dict->add( ‘name’, new cfstring( ‘john doe’ ) );
// kids namesjohnkyra
$dict->add( ‘kids names’, $array = new cfarray() );
$array->add( new cfstring( ‘john’ ) );
$array->add( new cfstring( ‘kyra’ ) );
/*
* 保存为 plist 为 xml文件
*/
$plist->savexml( __dir__.’/example-create-01.xml.plist’ );
/*
* 保存为 plist 为二进制文件
*/
$plist->savebinary( __dir__.’/example-create-01.binary.plist’ );
?>
(...)
read the rest of php类cfpropertylist操作plist文件 (210 words)
© lixiphp for lixiphp, 2013. | permalink | no comment |add to del.icio.us
post tags: cfpropertylist, library, php, plist, propertylist, 数据结构
feed enhanced by better feed from ozh