Example 1 — Column of Each Start Tag
Print the column of every start tag in a one-line XML string.
<?php
$xml = '<root><item id="1">Tea</item></root>';
$parser = xml_parser_create();
xml_set_element_handler(
$parser,
function ($parser, $name) {
echo $name, " starts at column ", xml_get_current_column_number($parser), PHP_EOL;
},
function ($parser, $name) {
}
);
xml_parse($parser, $xml, true); How It Works
- The XML is on a single line, so the column is the same as the character position.
- ROOT begins at the very start, which is column 0.
- <root> is 6 characters long, so ITEM begins at column 6.
- Names are upper case because the parser folds case by default.

