| Bookmarks |
'',
'INFO' => '',
'FOLDER' => '',
'TITLE' => '',
'BOOKMARK' => '',
'DESC' => ''
);
$close_tags = array(
'XBEL' => '',
'INFO' => '',
'FOLDER' => '',
'TITLE' => '',
'BOOKMARK' => '',
'DESC' => ''
);
function startElement($parser, $name, $attrs) {
global $open_tags, $current_tag, $depth, $tb, $hs, $na, $txt1, $txt2;
$current_tag = $name;
$hs++;
switch($name) {
case 'XBEL':
break;
case 'FOLDER':
array_push($txt2, "\n");
if (end($depth) == 'XBEL') {
$li = sprintf("", $na++);
//array_push($txt2, $li);
}
break;
case 'BOOKMARK':
//array_push($txt2, "\n");
$tb['url'] = $attrs['HREF'];
break;
default:
break;
}
array_push($depth, $name);
}
function endElement($parser, $name) {
global $close_tags, $tb, $current_tag, $depth, $hs, $txt2;
switch($name) {
case 'XBEL':
break;
case 'FOLDER':
array_push($txt2, "
\n");
break;
case 'BOOKMARK':
return_page($tb);
$tb = '';
break;
default:
break;
}
array_pop($depth);
$hs--;
}
function characterData($parser, $data) {
global $current_tag, $tb, $catID, $depth, $hs, $txt1, $txt2, $nb;
//$data = preg_replace('@&(.+?);@','{\\1}',htmlentities(utf8_decode($data)));
//$data = htmlentities(utf8_decode($data));
//print($data);
switch($current_tag) {
case 'BOOKMARK':
$tb['bookmark'] .= $data;
$current_tag = '';
break;
case 'TITLE':
$tpp = array_pop($depth);
if (end($depth) == 'FOLDER') {
if (trim($data) != '')
{
array_push($txt2, "- $data
\n");
$tpp2 = array_pop($depth);
if (end($depth) == 'XBEL') {
$li = sprintf("
%s", $nb++, $data);
array_push($txt1, $li);
}
array_push($depth, $tpp2);
}
} else {
$tb['title'] .= $data;
$current_tag = '';
}
array_push($depth, $tpp);
break;
case 'DESC':
$tpp = array_pop($depth);
if (end($depth) == 'BOOKMARK') {
$tb['desc'] .= $data;
$current_tag = '';
}
array_push($depth, $tpp);
break;
case 'URL':
$tb['url'] .= $data;
$current_tag = '';
break;
default:
break;
}
}
function return_page() {
global $tb, $txt2;
if ($tb['title']) {
$ll = sprintf(" - %s
\n", $tb['url'], rtrim($tb['title']));
if (!stristr($tb['title'],"cannabi"))
array_push($txt2, $ll);
//$ll1 = sprintf(" - %s", $tb['desc']);
//array_push($txt2, $ll1);
}
}
$xml_parser = xml_parser_create($type);
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
//xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'ISO-8859-1');
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
//$data = preg_replace('@&(.+?);@','{\\1}',htmlentities(utf8_decode($data)));
//print($data);
//$data = ereg_replace('&', '&', $data);
$data = ereg_replace('é','{eacute}',$data);
$data = ereg_replace('ç','{ccedil}',$data);
$data = ereg_replace('É','E',$data);
$data = ereg_replace('â','{acirc}',$data);
$data = ereg_replace('’','\'',$data);
$data = ereg_replace('ñ','{nieu}',$data);
$data = ereg_replace('ï','{iuml}',$data);
//$data = utf8_decode($data);
//echo $data;
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
reset($txt1);
/*foreach ($txt1 as $t) {
print $t;
}*/
reset($txt2);
foreach ($txt2 as $t) {
$t=ereg_replace("{ccedil}","ç",$t);
$t=ereg_replace("{nieu}","ñ",$t);
$t=ereg_replace("{acirc}","â",$t);
$t=ereg_replace("{eacute}","é",$t);
$t=ereg_replace("{iuml}","ï",$t);
print $t;
}
}
?>