phpjqueryphpquery

QueryPath outerHTML (jQuery for php)


I am using

gravitypdf/querypath (from composer)

I am trying to achieve this function from jQuery/JS in PHP QueryPath:

jQuery("html")[0].outerHTML;

I have tried the following:

echo (string) qp($html, $filter)->parents(":root"); // can't convert document to string

echo qp($html, $filter)->parents(":root")->html(); // returns inner HTML instead of outer HTML

edit, also tried:

echo qp($html, $filter)->parents(":root")->prop('outerHTML'); // prop doesn't exist

echo qp($html, $filter)->parents(":root")->outerHTML; // always returns empty string

// XMLSerializer JS object doesn't exist in PHP...

The issue is that the outerHTML property doesn't exist in queryPath...

please help me solve this...


Solution

  • Found this function in a unit test document:

    echo $doc->parents(":root")->get(0)->ownerDocument->saveXML();