XML 解析器

utf8_decode

<?php

var_dump(utf8_decode("\x66\x6f\x6f")); // string(3) "foo"

utf8_encode

<?php

var_dump(utf8_encode('foo')); // string(3) "foo"

xml_error_string

<?php

var_dump(xml_error_string(xml_get_error_code(xml_parser_create()))); // string(8) "No error"

xml_get_current_byte_index

<?php

var_dump(xml_get_current_byte_index(xml_parser_create())); // int(0)

xml_get_current_column_number

<?php

var_dump(xml_get_current_column_number(xml_parser_create())); // int(1)

xml_get_current_line_number

<?php

var_dump(xml_get_current_line_number(xml_parser_create())); // int(1)

xml_get_error_code

<?php

var_dump(xml_get_error_code(xml_parser_create())); // int(0)

xml_parse_into_struct

<?php

$parser = xml_parser_create();
$xml = <<<XML
          <?xml version="1.0" encoding="UTF-8"?>
          <document>
              <title>XML</title>
              <body>Here is some text.</body>
          </document>
          XML;
$array = [];
var_dump(xml_parse_into_struct($parser, $xml, $array)); // int(1)
var_dump($array);                                       // array(6) { [0]=> array(4) { ["tag"]=> string(8) "DOCUMENT" ["type"]=> string(4) "open" ["level"]=> int(1) ["value"]=> string(5) " " } [1]=> array(4) { ["tag"]=> string(5) "TITLE" ["type"]=> string(8) "complete" ["level"]=> int(2) ["value"]=> string(3) "XML" } [2]=> array(4) { ["tag"]=> string(8) "DOCUMENT" ["value"]=> string(5) " " ["type"]=> string(5) "cdata" ["level"]=> int(1) } [3]=> array(4) { ["tag"]=> string(4) "BODY" ["type"]=> string(8) "complete" ["level"]=> int(2) ["value"]=> string(18) "Here is some text." } [4]=> array(4) { ["tag"]=> string(8) "DOCUMENT" ["value"]=> string(1) " " ["type"]=> string(5) "cdata" ["level"]=> int(1) } [5]=> array(3) { ["tag"]=> string(8) "DOCUMENT" ["type"]=> string(5) "close" ["level"]=> int(1) } }

xml_parse

<?php

$parser = xml_parser_create();
$xml = <<<XML
          <?xml version="1.0" encoding="UTF-8"?>
          <document>
              <title>XML</title>
              <body>Here is some text.</body>
          </document>
          XML;
var_dump(xml_parse($parser, $xml)); // int(1)

xml_parser_create_ns

<?php

var_dump(xml_parser_create_ns()); // resource(4) of type (xml)

xml_parser_create

<?php

var_dump(xml_parser_create()); // resource(4) of type (xml)

xml_parser_free

<?php

var_dump(xml_parser_free(xml_parser_create())); // bool(true)

xml_parser_get_option

<?php

var_dump(xml_parser_get_option(xml_parser_create(), XML_OPTION_CASE_FOLDING));
var_dump(xml_parser_get_option(xml_parser_create(), XML_OPTION_SKIP_TAGSTART));
var_dump(xml_parser_get_option(xml_parser_create(), XML_OPTION_SKIP_WHITE));
var_dump(xml_parser_get_option(xml_parser_create(), XML_OPTION_TARGET_ENCODING));

xml_parser_set_option

<?php

var_dump(xml_parser_set_option(xml_parser_create(), XML_OPTION_CASE_FOLDING, 1));          // bool(true)
var_dump(xml_parser_set_option(xml_parser_create(), XML_OPTION_SKIP_TAGSTART, 0));         // bool(true)
var_dump(xml_parser_set_option(xml_parser_create(), XML_OPTION_SKIP_WHITE, 0));            // bool(true)
var_dump(xml_parser_set_option(xml_parser_create(), XML_OPTION_TARGET_ENCODING, 'UTF-8')); // bool(true)

xml_set_character_data_handler

<?php

/**
 * Just a test function.
 *
 * @param  void
 * @return void
 */
function foo()
{
    //
}

var_dump(xml_set_character_data_handler(xml_parser_create(), 'foo')); // bool(true)

xml_set_default_handler

<?php

/**
 * Just a test function.
 *
 * @param  void
 * @return void
 */
function foo()
{
    //
}

var_dump(xml_set_default_handler(xml_parser_create(), 'foo')); // bool(true)

xml_set_element_handler

<?php

/**
 * Just a test function.
 *
 * @param  void
 * @return void
 */
function foo()
{
    //
}

/**
 * Just a test function.
 *
 * @param  void
 * @return void
 */
function bar()
{
    //
}

var_dump(xml_set_element_handler(xml_parser_create(), 'foo', 'bar')); // bool(true)

xml_set_end_namespace_decl_handler

<?php

/**
 * Just a test function.
 *
 * @param  void
 * @return void
 */
function foo()
{
    //
}

var_dump(xml_set_end_namespace_decl_handler(xml_parser_create(), 'foo')); // bool(true)

xml_set_external_entity_ref_handler

<?php

/**
 * Just a test function.
 *
 * @param  void
 * @return void
 */
function foo()
{
    //
}

var_dump(xml_set_external_entity_ref_handler(xml_parser_create(), 'foo')); // bool(true)

xml_set_notation_decl_handler

<?php

/**
 * Just a test function.
 *
 * @param  void
 * @return void
 */
function foo()
{
    //
}

var_dump(xml_set_notation_decl_handler(xml_parser_create(), 'foo')); // bool(true)

xml_set_object

<?php

class Foo
{
    //
}

var_dump(xml_set_object(xml_parser_create(), new Foo())); // bool(true)

xml_set_processing_instruction_handler

<?php

/**
 * Just a test function.
 *
 * @param  void
 * @return void
 */
function foo()
{
    //
}

var_dump(xml_set_processing_instruction_handler(xml_parser_create(), 'foo')); // bool(true)

xml_set_start_namespace_decl_handler

<?php

/**
 * Just a test function.
 *
 * @param  void
 * @return void
 */
function foo()
{
    //
}

var_dump(xml_set_start_namespace_decl_handler(xml_parser_create(), 'foo')); // bool(true)

xml_set_unparsed_entity_decl_handler

<?php

/**
 * Just a test function.
 *
 * @param  void
 * @return void
 */
function foo()
{
    //
}

var_dump(xml_set_unparsed_entity_decl_handler(xml_parser_create(), 'foo')); // bool(true)

results matching ""

    No results matching ""