Search code examples
phphtmldomphpquery

getting the node value in phpquery


I am trying to get the node value from phpquery after scraping my html page.

$doc = phpQuery::newDocumentFileHTML('myurl');

foreach($doc['#filter-reload.row h1'] as $value)
{
print_r($value);
exit;
}

I am getting output as

DOMElement Object ( [tagName] => h1 [schemaTypeInfo] => [nodeName] => h1 
[nodeValue] => Oz The Great And Powerful (PG) [nodeType] => 1 [parentNode] => (object value omitted) 
[childNodes] => (object value omitted) [firstChild] => (object value omitted) [lastChild] => (object value omitted) [previousSibling] => (object value omitted)

I just want the nodeValue as output...But hw to get it ?

I tried:-

$doc['#filter-reload.row h1']->nodeValue //not working
$doc['#filter-reload.row h1']['nodeValue']//notworking

Solution

  • Try this out it will work.......

    $doc = phpQuery::newDocumentFileHTML('myurl');
    $new_data = array();
    foreach($doc['#filter-reload.row h1'] as $value)
    {
        $new_data[] = $value->nodeValue;
    }