Tryag File Manager
Home
-
Turbo Force
Current Path :
/
home
/
cluster1
/
data
/
bu01
/
1121861
/
html
/
jlex
/
php4
/
Upload File :
New :
File
Dir
//home/cluster1/data/bu01/1121861/html/jlex/php4/field_size_counter.php4
<? class field_size_counter { var $field_sizes; var $data; var $parser; function field_size_counter() { $this->field_sizes = array(); $this->data = ""; } function startHandler($xp, $element, $attribs) { //echo "START: $element \n"; //$element = strtolower($element); } function endHandler($xp, $element) { //echo "END: $element \n"; $element = strtolower($element); $size = strlen($this->data); if(array_key_exists($element,$this->field_sizes)) { $max = $this->field_sizes[$element]; if($size > $max) { $this->field_sizes[$element] = $size; } } else { $this->field_sizes[$element] = $size; } $this->data = ""; } function cDataHandler($xp, $data) { $data = trim($data); if($data != "") { $data = ereg_replace("&","&",$data); $data = ereg_replace("<","<",$data); $data = ereg_replace(">",">",$data); $this->data .= $data; } } function get_field_sizes($xml) { $in = fopen($xml,"r"); $this->parser = xml_parser_create(); xml_set_object($this->parser,$this); xml_set_element_handler($this->parser,"startHandler","endHandler"); xml_set_character_data_handler($this->parser,"cDataHandler"); while($line = fgets($in)) { $line = ereg_replace("&","&",$line); $good_parse = xml_parse($this->parser,$line,false); if(!$good_parse) { echo "there was an error <BR>"; } } xml_parser_free($this->parser); return $this->field_sizes; } } /* //error_reporting(0); set_time_limit(20000); $counter = new field_size_counter(); $sizes = $counter->get_field_sizes("modified_ActiveNahuatl_2005_august_final.xml"); foreach($sizes as $field=>$size) { echo "$field : $size \n"; } */ ?>