我可以分析一个plist文件用PHP和那种把它变成一个数组,像$_POST['']
,所以我可以打电话$_POST['body']
并获得具有<key> body
字符串?如何用php解析.plist文件?
13
A
回答
22
1
谷歌搜索“PHP解析器的plist”止跌回升this博客文章,这似乎是能够做你所要求的。
0
看了看一些库在那里,但他们有外部的要求,似乎矫枉过正。这是一个简单地将数据放入关联数组的函数。这对我尝试过的几个导出的iTunes plist文件起作用。
// pass in the full plist file contents
function parse_plist($plist) {
$result = false;
$depth = [];
$key = false;
$lines = explode("\n", $plist);
foreach ($lines as $line) {
$line = trim($line);
if ($line) {
if ($line == '<dict>') {
if ($result) {
if ($key) {
// adding a new dictionary, the line above this one should've had the key
$depth[count($depth) - 1][$key] = [];
$depth[] =& $depth[count($depth) - 1][$key];
$key = false;
} else {
// adding a dictionary to an array
$depth[] = [];
}
} else {
// starting the first dictionary which doesn't have a key
$result = [];
$depth[] =& $result;
}
} else if ($line == '</dict>' || $line == '</array>') {
array_pop($depth);
} else if ($line == '<array>') {
$depth[] = [];
} else if (preg_match('/^\<key\>(.+)\<\/key\>\<.+\>(.+)\<\/.+\>$/', $line, $matches)) {
// <key>Major Version</key><integer>1</integer>
$depth[count($depth) - 1][$matches[1]] = $matches[2];
} else if (preg_match('/^\<key\>(.+)\<\/key\>\<(true|false)\/\>$/', $line, $matches)) {
// <key>Show Content Ratings</key><true/>
$depth[count($depth) - 1][$matches[1]] = ($matches[2] == 'true' ? 1 : 0);
} else if (preg_match('/^\<key\>(.+)\<\/key\>$/', $line, $matches)) {
// <key>1917</key>
$key = $matches[1];
}
}
}
return $result;
}
相关问题
- 1. 如何解析Java中的.plist文件?
- 2. 如何解析值plist文件
- 3. 如何用PHP解析文件
- 4. 如何使用PHP解析robots.txt文件?
- 5. 如何使用PHP解析Excel文件
- 6. 在WP7中解析iOS .plist文件
- 7. 在Python中解析plist文件
- 8. 解析.plist文件中的问题
- 9. iOS - plist文件解析错误
- 10. 解析.plist文件为普通XML C#
- 11. 解析android中的Plist文件
- 12. 解析Android中的Apple Plist文件
- 13. 如何存储.plist文件中解析的JSON?
- 14. 用php解析xml文件
- 15. 解析cfg文件用php
- 16. 用php解析javascript文件
- 17. 解析XML的plist
- 18. C++ Plist解析器
- 19. 解析.plist项目
- 20. 如何在php中解析lua文件
- 21. 如何在PHP中解析XML文件
- 22. 如何在PHP中解析XML文件?
- 23. 如何在PHP中解析.eml文件?
- 24. php - 如何解析博客rss文件
- 25. 如何解析CSV文件在PHP
- 26. 如何在php中解析.msg文件?
- 27. NSXMLParser。如何解析KVC-plist-thingamajig-like XML?
- 28. 解析php文本文件
- 29. 如何强制Intellij IDEA将PHP文件解析为PHP文件
- 30. 存在任何delphi类来解析.plist osx文件
我...这是使用正则表达式,试图解析XML? – 2016-02-12 21:35:20
xml解析器将plist项的键/值作为单独的实体放置在轨道中。这将它们作为关键值赋予数组。 /耸耸肩 – 2016-02-13 19:25:13
你依靠有新行和专门形成的XML标签。 – 2016-02-13 19:56:05