I can start you off, I am unsure on searching arrays (never had to do it).. but this will display all of the bookmarks, and sort-of attempt to search it.
The $search you can bring in like $search = $_POST['search'];
Good Luck
<?php
$simple=@join('',@file('xbel.xml'));
$p = xml_parser_create();
xml_parse_into_struct($p, $simple, $vals, $index);
xml_parser_free($p);
$bm=array();
/*
foreach ($index['FOLDER'] as $k=>$v) // comment out since you have no folders
{
$bm[$v]='DDDODDD';
}
*/
$bm[0] = 'Bookmarks'; // The title
foreach ($index['TITLE'] as $k=>$v)
{
$bm[$v]=$vals[$v]['value'];
}
foreach ($index['BOOKMARK'] as $k=>$v)
{
if (is_array($vals[$v]['attributes']))
{
$bm[$v]=$vals[$v]['attributes']['HREF'];
}
}
/*
echo "Index array\n";
print_r($index);
echo "\nVals array\n";
print_r($vals);
*/
ksort($bm);
$l=true;
foreach ($bm as $k=>$v)
{
if ($v=='DDDODDD')
{
if (!$l)
{
echo '</div>';
$l=true;
}
} else {
if (substr($v,0,4)=='http')
{
$lastlink=$v;
} else {
if (strlen(trim($v))>0)
{
if ($l)
{
$l=false;
echo '<h3>'.htmlspecialchars($v).'</h3>
<div style="border: 1px solid #cccccc; background-color: #eeeeee; padding: 20px;">';
} else {
echo '<li><a href="'.$lastlink.'">'.htmlspecialchars($v).'</a></li>
';
}
}
}
}
}
echo "<br>";
$searchar = array();
$r = 0;
foreach($bm as $one=>$two) {
echo "One: $one<br>\nTwo: $two<br>\n";
if ($one >= 1) {
$searchar[$r] = $two;
$r++;
}
}
// print_r($searchar);
$search = "Grant";
$found = array();
echo "<br><br>Searching for $search:<br><br>";
reset ($bm);
while (list ($key, $val) = each ($bm)) {
if (preg_match ("/$search/i", $val)) {
// print "A match was found in $key.<br />";
//echo "<br><br>".$bm[$key]."-".$bm[$key + 1];
if (preg_match('!(^|([^\'"]\s*))' .
'([hf][tps]{2,4}:\/\/[^\s<>"\'()]{4,})!mi',$bm[$key])) {
echo "<a href=\"".$bm[$key]."\">".$bm[$key + 1]."</a>";
}
$key = $lastkey;
} else {
// print "A match was not found in $key.<br />";
}
}
?>