" method="get"> Search:
" size="30">
'); } $xpath = $doc->xpath_new_context(); // Check if input data validates if (isset($_REQUEST["title"]) && isset($_REQUEST["imdb"]) && preg_match("#[a-zA-Z ',:\.!&]+#", $_REQUEST["title"]) && preg_match("|^http://(www.)?imdb.com/title/[a-z0-9]+/?$|", $_REQUEST["imdb"]) ) { $_REQUEST["title"] = stripslashes($_REQUEST["title"]); $movies = $xpath->xpath_eval("//movie"); // Extract last entry $lastmovie = $xpath->xpath_eval("//movie[last()]"); if (count($lastmovie->nodeset) > 0) { $lastmovie = $lastmovie->nodeset[0]; $id = $lastmovie->get_attribute("id") + 1; } else { $id = 1; } // Create a new movie element $root = $doc->document_element(); $movie = $doc->create_element("movie"); $titlenode = $doc->create_element("title"); $title = $doc->create_text_node($_REQUEST["title"]); $titlenode->append_child($title); $imdbnode = $doc->create_element("imdb"); $imdb = $doc->create_text_node($_REQUEST["imdb"]); $imdbnode->append_child($imdb); $movie->set_attribute("id", $id); $movie->append_child($titlenode); $movie->append_child($imdbnode); // Add movie to tree $root->append_child($movie); // Save xml string to disk. $doc->dump_file(XMLSOURCE); } // Show movie list $movies = $xpath->xpath_eval("//movie[contains(translate(title,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'), '".strtoupper($_REQUEST["search"])."')]"); print "Movie list
\n"; print "\n"; foreach ($movies->nodeset as $movie) { $title = ""; $imdb = ""; $id = $movie->get_attribute("id"); foreach ($movie->child_nodes() as $child) { if ($child->node_name() == "title") $title = $child->get_content(); if ($child->node_name() == "imdb") $imdb = $child->get_content(); } print " \n"; print " \n"; print " \n"; } print "
$title

\n"; print "Movies found: ".count($movies->nodeset)."\n"; ?>
" method="post"> Title:


IMDB url: