this was used to as a config for different file data rows.
basicly it would take the colm names for the config file, and file in the data for proper alignment.
php
<?php
function load_file_format($filename) {
$XMLPARSER = xml_parser_create();
xml_parser_set_option($XMLPARSER, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($XMLPARSER, XML_OPTION_SKIP_WHITE, 1);
$FILEGLOB = file_get_contents($filename);
//echo "<br>Error opening $filename";
xml_parse_into_struct($XMLPARSER, $FILEGLOB, $VALS, $IDX);
xml_parser_free($XMLPARSER);
unset($FILEGLOB);
// The tags we are concerned about are <filetype>
// Check for the opening and ending tags, then lump all the middle
// records together and pass off to the parseformat
foreach ($IDX as $key=>$value) {
//echo print_r($key)."=>".print_r($value)."\r\n";
if ($key == 'filetype') {
$range = $value;
// each pair is the low / high end of the tag
for ($i=0;$i < count($range); $i+=2) {
$offset = $range[$i] + 1;
$len = $range[$i+1] - $offset;
$DB[] = parse_format(array_slice($VALS,$offset,$len));
//run_log("//parse_format(array_slice($VALS,$offset,$len))");
}
} else {
continue;
}
}
return($DB);
}
// takes the passed array and returns it as a FileFormat class
// prefilled with the data in the array
function parse_format($vals) {
for ($i=0; $i < count($vals); $i++) {
$tmp[$vals[$i]["tag"]] = $vals[$i]["value"];
}
return($tmp);
}
?>
This post has been edited by SpaceMan: 3 Mar, 2008 - 07:21 AM