PHP xml_parser_create() 함수
예시
XML 파서를 만들고 XML 문서( note.xml )를 파싱합니다.
<?php
// Create an XML parser
$parser=xml_parser_create();
function char($parser,$data) {
echo $data;
}
xml_set_character_data_handler($parser,"char");
$fp=fopen("note.xml","r");
while ($data=fread($fp,4096)) {
// Parse XML data
xml_parse($parser,$data,feof($fp)) or
die (sprintf("XML Error: %s
at line %d",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
}
xml_parser_free($parser);
fclose($fp);
?>
정의 및 사용
xml_parser_create() 함수는 XML 파서를 생성합니다.
팁: xml 파서를 해제하려면 xml_parser_free() 함수를 사용하십시오.
팁: 네임스페이스를 지원하는 XML 파서를 생성하려면 xml_parser_create_ns() 함수를 대신 사용하십시오.
통사론
xml_parser_create(encoding)
매개변수 값
Parameter | Description |
---|---|
encoding | Optional. Specifies the character encoding for input/output in PHP 4. From PHP 5 it specifies the character encoding only for output. In PHP 5.0.0 and 5.0.1, the default output charset is ISO-8859-1. From PHP 5.0.2, the default output charset is UTF-8 |
기술적 세부 사항
반환 값: | 성공 시 다른 XML 함수에서 사용할 리소스 핸들입니다. 실패시 FALSE |
---|---|
PHP 버전: | 4.0+ |
❮ PHP XML 파서 참조