skip to Main Content

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…

2

Answers


  1. Chosen as BEST ANSWER

    Found this function in a unit test document:

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

  2. Have you tried

    $('html').prop('outerHTML')
    

    or

    $(document).outerHTML
    

    or

    new XMLSerializer().serializeToString(document)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search