Initial commit
This commit is contained in:
63
php/functions/func_xml.php
Normal file
63
php/functions/func_xml.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?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);
|
||||
}
|
||||
|
||||
################################################ FUNCTION: xml_nl_to_paragraph #
|
||||
function xml_nl_to_paragraph($string)
|
||||
{
|
||||
$string = '<p>'.preg_replace('#([\r\n]\s*?[\r\n]){2,}#','</p>$0<p>',$string).'</p>';
|
||||
$string = str_replace('<p></p>','',$string);
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
################################################### FUNCTION: xml_parse_bbcode #
|
||||
function xml_parse_bbcode($string)
|
||||
{
|
||||
$codes = array('[b]','[/b]','[i]','[/i]','[/link]');
|
||||
$translation = array('<strong>','</strong>','<em>','</em>','</a>');
|
||||
|
||||
// replace bbcode items from above
|
||||
$string = str_replace($codes,$translation,$string);
|
||||
|
||||
// deal with [link]s
|
||||
$pattern = "#\[link href=([^\]]+)\]#";
|
||||
$replacement = "<a href='$1' title='$1'>";
|
||||
$string = preg_replace($pattern,$replacement,$string);
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
###################################################### FUNCTION: xml_fix_cdata #
|
||||
function xml_fix_cdata($string)
|
||||
{
|
||||
$find[] = '<![CDATA[';
|
||||
$replace[] = '<![CDATA[';
|
||||
|
||||
$find[] = ']]>';
|
||||
$replace[] = ']]>';
|
||||
|
||||
return $string = str_replace($find, $replace, $string);
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user