I was writing a random search engine thing that uses XML databases instead of mySQL in case mySQL is not supported. It is a simple prgram, using one html page and two php pages. You have the ability to submit a site and to search for it, using one of the PHP pages for each.
I finished my pages and uploaded them to a PHP enabled server to check if they worked. They didn't. Straight away, I got this error message:
Fatal error: Call to undefined function: domxml_new_doc() in /home/lkvukayy/public_html/testxmlsearch/submit.php on line 3
The sumbit page is quite simple. It looks like this:
<?php
create_element("article");
$root = $doc->append_child($root);
$dh = opendir('./xml/');
while ($file = readdir($dh)){
$string = $id . “.xml”;
if (eregi("^\\.\\.?$", $file)) {
continue;
}
if (eregi($string, $file)){
$time = date("U"); /
$id = $id . "-" . $time;
}
}
$root->set_attribute('id', $id);
$site = $doc->create_element("website");
$site = $root->append_child($site);
$stext = $doc->create_text_node($website);
$stext = $site->append_child($stext);
$keylisting = $doc->create_element("keywords");
$keylisting = $root->append_child($keylisting);
$ktext = $doc->create_text_node($keywords);
$ktext = $keylisting->append_child($ktext);
$filename = "./xml/".$id . ".xml";
$doc->dump_file($filename, false, true);
header("Location:search.htm");
?>
The search.htm [page looks like this:
<html>
<head>
<title>Submit/search a Site...</title>
<script>
function isReady(form){
if(form.site.value == "") {
alert("Please enter an website!");
return false;
}
}
</script>
</head>
<body>
<h1>Submit a Website to Search Function</h1>
<a href="www.google.com">Cancel</a><br><br>
<form name="createArticle" action="submit.php" method="post" onSubmit="return isReady(this)">
<table border=0 cellspacing=0 cellpadding=3>
<tr valign=top>
<td width="135">Website URL</td>
<td width="634"> <input name="site" type="text" id="site"> <br> <font size="-1">(no
spaces, must be unique)</font></td>
</tr>
<tr valign=top>
<td>Keywords</td>
<td><input name="keywords" type="text" id="keywords"> <br> <font size="-1">(separate keywords
with commas)
<input type="hidden" name="id" id="id" value="1">
<input type="hidden" name="status" value="in progress"></td>
</tr>
</table>
</form>
<br><br><br>
<form name="search" method="post" action="searchsites.php">
Search articles:
<input name="search" type="text" id="search">
<input name="Search" type="submit" id="Search" value="Search">
</form>
</div>
</body></html>
And the search for a site php page looks like this:
<?php
session_start();
$results = array();
//this is a very simple, potentially very slow search
function extractText($array){
if(count($array) <= 1){
//we only have one tag to process!
for ($i = 0; $i<count($array); $i++){
$node = $array[$i];
$value = $node->get_content();
}
return $value;
}
}
$dh = opendir('./xml/');
while ($file = readdir($dh)){
if (eregi("^\\.\\.?$", $file)) {
continue;
}
$open = "./xml/".$file;
$xml = domxml_open_file($open);
//we need to pull out all the things from this file that we will need to
//build our links
$root = $xml->root();
$k_array = $root->get_elements_by_tagname("keywords");
$keywords = extractText($k_array);
if (eregi($searchTerm, $keywords)){
$list['website'] = $stext;
$results[] = $list;
}
}
$results = array_unique($results);
?>
<h1>Search Results</h1>
<p>You searched for: <i><?php echo $searchTerm ?></i></p>
<hr>
<?php
if (count($results)>0){
echo "<p>Your search results:</p>";
foreach ($results as $key => $listing){
echo "<br>" . $listing["website"]."\n";
echo "<br>";
}
} else {
echo "<p>No websites matched your search term. Please try again with different keywords, or go <a href="search.php">home</a>.";
}
?>
Sorry for the long post... Can anyone help? It would be really appreciated. Thanks in advance.