2009-11-17 10 views
13

PHPでplistファイルを解析して、$_POST['']のような配列に取得することができますので、$_POST['body']を呼び出して<key> bodyの文字列を取得できますか? 「PHP plistをパーサ」のためにグーグルでphplで.plistファイルを解析するには?

答えて

1

は、あなたが求めているものを行うことができるように思わ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; 
} 
+0

私はXMLを試して解析するために正規表現を使用していますか? –

+0

xmlパーサは、plistエントリのキー/値を別のエンティティとしてトラックに配置します。これは、それらをキー値帰属配列として置きます。/shrug –

+0

あなたは新しい行があり、特にXMLタグが形成されていることに頼っています。 –

関連する問題