在苹果IOS开发过程中,经常会用到plist格式的文件,它是一种XML格式文件,本文主要基于xml原理来解析plist文件。 Plist 文件格式 本文解析的plist文件格式如下: ?xml version="1.0" encoding="UTF-8"? !DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST
在苹果IOS开发过程中,经常会用到plist格式的文件,它是一种XML格式文件,本文主要基于xml原理来解析plist文件。
Plist 文件格式
本文解析的plist文件格式如下:
<?xml version="1.0" encoding="UTF-8"?> <plist version="1.0"> <dict> <dict> <key>KEY1</key> <string>KEY_VALUE</string> </dict> <key>KEY2</key> <array> <dict> <key>KEY2_key1</key> <string>KEY2_key1_value1</string> </dict> <dict> <key>KEY2_key2</key> <string>KEY2_key2_value1</string> </dict> </array> </dict> </plist>
从上面的格式我们可以通过定义xml解析函数来获取数据。
使用PHP XML 解析器函数
//会用到的全部变量 global $xml_parser,$songs,$number_dicts,$current_key,$current_element,$current_data,$end_of_songs;//文件路径 $target = ‘FILE_Path’; //文件名称 $filename = ‘FILE_Name’;//建立一个 XML 解析器 $xml_parser = xml_parser_create(); xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 1); xml_set_element_handler($xml_parser, "start_element", "end_element"); xml_set_character_data_handler($xml_parser, "character_data");if (!($fp = @fopen($target, "r"))) { return false; }while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { die(sprintf("XML error: %s at line %d in file %s\n", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser), $filename)); } }//释放指定的 XML 解析器 xml_parser_free($xml_parser);
文件主要部分负责建立XML解析器和定义元素处理器和字符数据处理器。
(...)
Read the rest of PHP解析XML格式的Plist文件 (340 words)
© lixiphp for LixiPHP - 致力于PHP高级编程!, 2013. | Permalink | No comment |
Add to del.icio.us
Post tags: PHP, plist, XML
Feed enhanced by Better Feed from Ozh

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version