|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-03-03 12:37 UTC] preben at infofab dot no
[2006-03-03 12:37 UTC] preben at infofab dot no
[2006-03-07 02:17 UTC] vrana@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 22:00:02 2025 UTC |
Description: ------------ The function xml_get_current_byte_index() returns byte index according to utf8 encoded text - disregarding if input is in ISO-8859-1. If you would like to cach a chunk of data from a xml file you would need to convert input to utf8 to get the correct calculations. Reproduce code: --------------- $data = "<?xml version='1.0' encoding='iso8859-1'?>\n<data>\n<dummy>????</dummy>\n<row>???data</row>\n</data>\n"; function startElement($parser, $name, $attrs) { global $data; if($name != "ROW") return; $byte = xml_get_current_byte_index($parser) + 41; $ch = substr($data, $byte + 41, 7); # The following calculates correct # $ch = utf8_decode(substr(utf8_encode($data), $byte, 7)); echo "$name ($byte): $ch\n"; exit(); } function endElement($parser, $name) { } $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_parse($xml_parser, $data, 1); Expected result: ---------------- ROW (79): ???d Actual result: -------------- ROW (79):