blue puppies<|>images/07193a.jpg<|>Big blue puppies!
*/
$datafile="links.txt";
$_sep="<|>"; /* delimiter (separator) used in $datafile */
/*
* The number of $_keys must be 1 less than the number of fields per line.
* These will be used as:
*
* $hash_ar[field0][count]=array (
* $_key[0] => field1,
* $_key[1] => field2,
* ...
* $_key[n] => fieldn
* )
*/
$_keys=array("name", "url", "desc");
/* html */
$head ="\n";
$head.="\n";
$head.="\n";
$head.="
\n";
$head.=" \n";
$head.=" \n";
$head.=" " . $h_name . " - " . $_self . "\n";
$head.=" \n";
$head.=" \n";
$head.=" \n";
/*
* END VARs
*/
/*
* FUNCTIONS
*/
/* main hash function for $datafile */
function hash_dat($datafile)
{
global $debug, $_sep, $_keys, $hash_ar;
$dat_ar=file($datafile);
sort($dat_ar);
reset($dat_ar);
for ($line=0; $line < count($dat_ar); $line++) {
$current=trim($dat_ar[$line]);
$current=stripcslashes($current);
// parts[0] ... parts[n] = fields of current line
$parts=explode($_sep,$current);
// parts[0] is the sort key
$_c=$parts[0];
// current number of lines matching current sort key
$_c_cnt=count($hash_ar["$_c"]);
for ($k_cnt=0; $k_cnt < count($_keys); $k_cnt++){
$p_cnt=$k_cnt + 1; // skip the first field (sort field)
$_k=$_keys[$k_cnt]; // current key
$_val=$parts[$p_cnt]; // current value for key in key => val
$hash_ar["$_c"]["$_c_cnt"]["$_k"]="$_val";
}
}
}
/*
* a function to show vars in an html page to aid in debugging
*/
function print_r_debug($ar,$_tag)
{
echo " \n";
echo " $_tag
\n";
echo "\n";
print_r($ar);
if ( is_array($ar) ) {
reset($ar);
echo " $_tag reset\n";
} else {
echo "\n";
}
echo "\n";
echo " \n";
}
/*
* END FUNCTIONS
*/
/*
* MAIN
*/
hash_dat($datafile);
echo $head;
echo "
\n";
/* produce a line of anchor tags from the array keys */
reset($hash_ar);
while (list($key,) = each($hash_ar)){
echo "
$key \n";
}
echo "
\n";
/* main body of links */
foreach ($hash_ar as $cat => $ar){
echo "
\n";
echo " \n";
echo " \n";
echo " $cat\n";
echo " \n";
echo " [top]
\n";
echo "
\n";
foreach ($ar as $num => $val){
$_n=$val["$_keys[0]"];
$_u=$val["$_keys[1]"];
$_d=$val["$_keys[2]"];
echo " - \n";
echo " \n";
echo " $_n\n";
echo " \n";
if ($_d != ""){
echo " $_d \n";
}
echo "
\n";
}
echo "
\n";
}
echo " \n";
echo "\n";
/*
* END MAIN
*/
?>