Files
d-t-n.org/production/php/functions/func_xml.php
2017-03-02 21:36:05 -06:00

25 lines
550 B
PHP

<?php
################################################### FUNCTION: xml_random_child #
function xml_random_child($xml_file)
{
$xml = xml_get_from_file($xml_file);
$children = $xml->children();
$count = count($children);
return($children[rand(0,$count-1)]);
}
################################################## FUNCTION: xml_get_from_file #
function xml_get_from_file($file_path)
{
if(!file_exists($file_path))
{
trigger_error('XML file "'.$file_path.'" does not exist!');
return NULL;
}
return simplexml_load_file($file_path);
}
?>