Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7877081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:16:34+00:00 2026-06-03T03:16:34+00:00

I have errors when I want to print the result of an evaluate expression

  • 0

I have errors when I want to print the result of an evaluate expression with XPath.

$url = $xpath->evaluate(‘//a/@href’, $event);
echo $url ;

I have this error : Catchable fatal error: Object of class DOMNodeList could not be converted to string

My code :

<?php
    // Get the HTML Source Code
    $url='http://www.parisbouge.com/events/2012/05/01/';
    $source = file_get_contents($url);

    // DOM document Creation
    $doc = new DOMDocument;
    $doc->loadHTML($source);

    // DOM XPath Creation
    $xpath = new DOMXPath($doc);

    // Get all events
    $events = $xpath->query('//li[@class="nom"]');

    // Count number of events
    printf('There is %d events<br />', $events->length);

    // List all events
    for($i = 0; $i < ($events->length); $i++) {
        $event = $events->item($i);
        $url = $xpath->evaluate('//a/@href', $event);
        $nom = $xpath->evaluate('//a/text()', $event);
        $lieu = $xpath->evaluate('../li[@class="lieu"]/a/text()', $event);
        echo "Result : $url $nom $lieu <br/>";
    }
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:16:35+00:00Added an answer on June 3, 2026 at 3:16 am

    Try this to get information about nodes.

     // List all events
    for($i = 0; $i < ($events->length); $i++) {
        $event = $events->item($i);
        $url = $xpath->evaluate('.//a/@href', $event);
        $nom = $xpath->evaluate('.//a/text()', $event);
        $lieu = $xpath->evaluate('../li[@class="lieu"]/a/text()', $event);
    
        $result = '';
        if ($url->length > 0) {
            $result .= $url->item(0)->value;
        }
    
        if ($nom->length > 0) {
            $result .= $nom->item(0)->wholeText;
        }
    
        if ($lieu->length > 0) {
            $result .= $lieu->item(0)->wholeText;
        }
    
        echo $result . "<br />";
        //echo "Result : " . $url->item(0)->value . ' | ' . $nom->item(0)->wholeText  . ' | ' . $lieu->item(0)->wholeText . "<br/>";
    }
    

    Don’t forget add checking if node exists etc. To check if there is any nodes you can check nodeList lenght or suppres errors how “Gordon” suggested.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have many errors in my apache error log like this: [Mon Mar 26
I have the following barchart to which I want to add error bars. library(lattice)
I have a multi-lingual page where I want to display form validation error in
I have VB6 application , I want to put some good error handling finction
i have a problem with my Android Application. The Error occures when i want
Hi guys I wrote this code and i have two errors. Invalid rank specifier:
Let's say we have def Foo(Bar=0,Song=0): print(Bar) print(Song) And I want to assign any
I want to upload and get the result from this website. http://cello.life.nctu.edu.tw/ I tried
I want in output this PHP code echo name , star_type , service by
I have inherited a poorly written web application that seems to have errors when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.