Jump to content

Need Help with DOMXpath


hieK

Recommended Posts

so i am trying to make my api for a website, and started coding a script for it.

 

so far it looks like this

 

<?php
 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$rt = curl_exec($ch);
 
$dom = new DOMDocument();
@$dom->loadHTML($rt);
 
$xpath = new DOMXpath($dom);
 
// title ("//h1[@class=textLarge7 extratextLarge7]/text()")
 
$titleQuery = $xpath->query("//h1[@class=textLarge7 extratextLarge7]/text()");
echo $titleQuery;

 

 

 
the problem is that when i try to echo it it wont give me the title ( only an error on line 17, that is the last line )
 
if it helps you when i try to execute print_r it gives me DOMNodeList Object ( )
 
Sorry for my bad english, its not my native language

index.php

Link to comment
https://forums.phpfreaks.com/topic/290874-need-help-with-domxpath/
Share on other sites

So now i have another problem,

 

<ul class="listType1 marginTop1">
<li itemprop="ingredients">13/4 pahar faina de naut</li>
<li itemprop="ingredients">3/4 lingurita de sare</li>
<li itemprop="ingredients">3/4 lingurita cardamon macinat marunt</li>
<li itemprop="ingredients">1/2 lingurita piper negru macinat</li>
<li itemprop="ingredients">11/2 pahare de apa</li>
<li itemprop="ingredients">4 linguri ulei de masline</li>
</ul>
 
i cant figure out how to write the xpath query
 
$ingredientsQuery = $xpath->query("//ul[@class=listType1 marginTop1]/text()"); but how do i integrate the li ?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.