我可以分析一個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