?Include/Req dynamic file?
Posted: Fri Feb 14, 2003 8:13 pm
Code: Select all
<?
global $bsnews;
function file_to_array($news_url, $seperator)
{
//Get Contents
$bsnews['prearray'] = require($news_url);
//Strip tags
$bsnews['prearray'] = strip_tags($bsnews['content']);
//Add Delimiters
$bsnews['prearray'] = str_replace("2003", "|2003", $bsnews['prearray']);
//Add ending delmiter
$bsnews['prearray'] .= $seperator;
//Explode to level one
$bsnews['array'] = explode($seperator, $bsnews['prearray']);
//Remove Blank Keys
$bsnews['array'] = array_slice($bsnews['array'], 1, -1);
//Loop and explode to level two
for($i = 0; $i < count($bsnews['array']); $i++)
{
//Explode Key
$bsnews['array2'][$i] = explode(" ", $bsnews['array'][$i]);
//Assign Key0 to Date
$bsnews['final'][$i]['date'] = $bsnews['array2'][$i]['0'];
//Assign Key1 to Contest
$bsnews['final'][$i]['contest'] = $bsnews['array2'][$i]['1'];
//Assign Key2 to Content
$bsnews['final'][$i]['content'] = $bsnews['array2'][$i]['2'];
}
//Return $BattleSpotNews
return $bsnews;
}
//Test function
file_to_array("http://www.battlespot.com/mindrover/news/dump?r=", "|");
//Additional Test, Print the array.
print_r($bsnews['final']);
?>