Hàm xml_parser_create () trong PHP
❮ Tham chiếu trình phân tích cú pháp XML PHP
Thí dụ
Tạo trình phân tích cú pháp XML và phân tích cú pháp tài liệu 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);
?>
Định nghĩa và Cách sử dụng
Hàm xml_parser_create () tạo một trình phân tích cú pháp XML.
Mẹo: Để giải phóng trình phân tích cú pháp xml, hãy sử dụng hàm xml_parser_free () .
Mẹo: Để tạo trình phân tích cú pháp XML có hỗ trợ không gian tên, hãy sử dụng hàm xml_parser_create_ns () để thay thế.
Cú pháp
xml_parser_create(encoding)
Giá trị tham số
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 |
Chi tiết kỹ thuật
Giá trị trả lại: | Một xử lý tài nguyên sẽ được sử dụng bởi các hàm XML khác khi thành công. FALSE khi thất bại |
---|---|
Phiên bản PHP: | 4.0+ |
❮ Tham chiếu trình phân tích cú pháp XML PHP