function _parser_text_no_function_($xml, $rootelement = "") { global $charset; $vals = array(); $index = array(); if ($xml) { $simple = $xml; $rx = "/<?xml.*encoding=[\\'\"](.*?)[\\'\"].*?>/m"; if (preg_match($rx, $simple, $m)) { $encoding = strtoupper($m[1]); } else { $encoding = "ISO-8859-1"; } //encodages supportés par les fonctions suivantes if ($encoding != "ISO-8859-1" && $encoding != "UTF-8" && $encoding != "US-ASCII") { $encoding = "ISO-8859-1"; } $p = xml_parser_create($encoding); xml_parser_set_option($p, XML_OPTION_TARGET_ENCODING, $charset); xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, 1); if (xml_parse_into_struct($p, $simple, $vals, $index) == 1) { xml_parser_free($p); $param = array(); $tag_count = array(); $indice = 0; _recursive_($indice, 1, $param, $tag_count, $vals); } unset($vals, $index); if (is_array($param)) { if ($rootelement) { if (count($param[$rootelement]) != 1) { echo "Erreur, ceci n'est pas un fichier {$rootelement} !"; exit; } $param_var = $param[$rootelement][0]; } else { $param_var = $param; } return $param_var; } } }
function _parser_text_no_function_($xml, $rootelement) { global $charset; $vals = array(); $index = array(); if ($xml) { $simple = $xml; $rx = "/<?xml.*encoding=[\\'\"](.*?)[\\'\"].*?>/m"; if (preg_match($rx, $simple, $m)) { $encoding = strtoupper($m[1]); } else { $encoding = "ISO-8859-1"; } $p = xml_parser_create($encoding); // xml_parser_set_option($p, XML_OPTION_TARGET_ENCODING, $charset); xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, 1); if (xml_parse_into_struct($p, $simple, $vals, $index) == 1) { xml_parser_free($p); $param = array(); $tag_count = array(); $p1 = 0; $p2 = 1; _recursive_($p1, $p2, $param, $tag_count, $vals); } else { echo xml_error_string(xml_get_error_code($p)) . " " . xml_get_current_line_number($p); } unset($vals, $index); if (is_array($param)) { if (count($param[$rootelement]) != 1) { echo "Erreur, ceci, n'est pas un fichier {$rootelement} !"; exit; } $param_var = $param[$rootelement][0]; return $param_var; } } }
function _recursive_($set, &$current, $value, $i, $length) { if ($length - 1 == $i) { $current[$set[$i]] = $value; } else { _recursive_($set, $current[$set[$i]], $value, $i + 1, $length); } }