My PHP code give some error! In the root..

Discussion in 'PHP' started by Mrbagino, Dec 1, 2012.

  1. #1
    Dear all,

    I have some problem with my php code i try to make some XML and PHP Content managmant system, but i have now some problem with the root?

    He give the next error: Fatal error: Call to a member function root() on a non-object in /home/......./public_html/searchArticles.php on line 29


    See here my code please:
    
    <?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("id");
    
    $id = $root->get_attribute("id");
    
    $stat_array = $root->get_elements_by_tagname("status");
    $status = extractText($stat_array);
    
    $k_array = $root->get_elements_by_tagname("keywords");
    $keywords = extractText($k_array);
    
    $h_array = $root->get_elements_by_tagname("headline");
    $headline = extractText($h_array);
    
    $ab_array = $root->get_elements_by_tagname("abstract");
    $abstract = extractText($ab_array);
    
    if ($status != "live"){
    continue;
    }
    
    if (eregi($searchTerm, $keywords) or eregi($searchTerm,$headline)){
    $list['abstract'] = $abstract;
    $list['headline'] = $headline;
    $list['file'] = $file;
    $results[] = $list;
    }
    
    }
    
    $results = array_unique($results);
    
    ?>
    <h1>Search Results</h1>
    <a href="index.php">back to main</a>
    <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><a href=\"showArticle.php?file=".$listing["file"]."\">" . $listing["headline"]."</a>\n";
    echo "<br>". $listing["abstract"];
    echo "<br>";
    }
    } else {
    
    echo "<p>Sorry, no articles matched your search term.</p>";
    }
    
    ?>
    PHP:

    I hope for some sugestions, Thanks a lot!
     
    Mrbagino, Dec 1, 2012 IP
  2. ronaldsg

    ronaldsg Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    What is supposed to happen in this line?
    
    $xml = "domxml_open_file" .$open;
    
    PHP:
    This creates a string, but on next line $xml object is expected, that's why it fails.
     
    ronaldsg, Dec 1, 2012 IP
  3. Mrbagino

    Mrbagino Greenhorn

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    Thanks for the help,

    Maby a stuped ask but what do you mean with the object is expected?
     
    Mrbagino, Dec 1, 2012 IP
  4. ronaldsg

    ronaldsg Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    ronaldsg, Dec 1, 2012 IP