댓글 검색 목록

[php] Convert XML to JSON in PHP

페이지 정보

작성자 운영자 작성일 15-06-02 23:34 조회 1,991 댓글 0

function XMLtoJSON($xml) {

  $xml = file_get_contents($xml);    // gets XML content from file

  $xml = str_replace(array("\n", "\r", "\t"), '', $xml);    // removes newlines, returns and tabs

 

  // replace double quotes with single quotes, to ensure the simple XML function can parse the XML

  $xml = trim(str_replace('"', "'", $xml));

  $simpleXml = simplexml_load_string($xml);

 

  return stripslashes(json_encode($simpleXml));    // returns a string with JSON object

댓글목록 0

등록된 댓글이 없습니다.

웹학교 로고

온라인 코딩학교

코리아뉴스 2001 - , All right reserved.