2009-11-17 6 views

답변

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 태그가 의존하고 있습니다. –

관련 문제