일상 기록 창고

simplexml_load_file 예제코드 본문

프로그래밍/PHP

simplexml_load_file 예제코드

Crazy_Kong 2009. 6. 2. 10:32

 simplexml_load_file 예제 코드

 

 $url = 'test.xml';

 if($xml = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA))
 {
  $result["nSeqNo"]   = $xml->xpath("/channel/item/nSeqNo");
  $result["sCode"]    = $xml->xpath("/channel/item/sCode");
  $result["sCategory"] = $xml->xpath("/channel/item/sCategory");
  $result["sCodeTitle"] = $xml->xpath("/channel/item/sCodeTitle");
  $result["sCategoryTitle"] = $xml->xpath("/channel/item/sCategoryTitle");

  foreach($result as $key => $attribute)
  {
   $i=0;
   foreach($attribute as $element)
   {
    $ret[$i][$key] = (string)$element;
    $i++;
   }
  }
  echo "<pre>";
  print_r ($ret);
  echo "</pre>";
 }

'프로그래밍 > PHP' 카테고리의 다른 글

strtotime 사용  (0) 2009.06.08
이미지 추출 정규식  (0) 2009.06.08
주민번호로 생년월일 추출  (0) 2009.05.19
파일 크기 구하는 함수  (0) 2009.05.19
확장자 구하기  (0) 2009.05.19