I'm working with parsing xml using php and have successfully output html but what I really want to do is sort the output alphabetically with regard to the extension, much like it could be done using xsl/xslt. I have tried sorting the $data array via the character_data function but that returns
Warning: Wrong datatype in sort() call in c:\nusphere\apache\htdocs\iaa\filetypes.php on line 51
Warning: Variable passed to reset() is not an array or object in c:\nusphere\apache\htdocs\iaa\filetypes.php on line 52
.
So any suggestions or pointers to where might help?
<?
$openfile = ('filetypes.xml');
$start = array ('type' => '<div id="content"><span class="title">',
'file' => '<div id="packetholder">',
'extension' => '<span class="title">',
'definition' => '<span class="description">',
'uses' => '<span class="url">');
$end = array ( 'type' => '</span></div>',
'file' => '</div>',
'extention' => '</span><br />',
'definition' => '</span><br />',
'uses' => '</span>');
function start_html($parser, $element_name)
{
global$start;
echo $start[strtolower($element_name)];
}
function end_html($parser, $element_name)
{
global$end;
echo $end[strtolower($element_name)];
}
function character_data($parser, $data)
{
sort
echo $data;
}
$parser = xml_parser_create();
xml_set_element_handler($parser, 'start_html', 'end_html');
xml_set_character_data_handler($parser, 'character_data');
$fp = fopen($openfile, 'r') or die('couldnt open file');
while ($data = fread($fp, 4096))
{
xml_parse($parser, $data, feof($fp))
or die (sprintf('XML Error: %s at line %d',
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
}
xml_parser_free($parser);
?>