phpdomparserphpquery

phpQuery for current file


I am just trying to get started with phpQuery DOM Parser but I don't understand how to load the current php file so that I can play with elements in this particular page.

Say I have a php file about.php. It has a simple markup:

<?php
    require('phpQuery/phpQuery.php');
    phpQuery::newDocument();
    pq('div')->addClass('myclass'); // this doesn't work
?>
<html>
    <head>
        <title>About</title>
    <head>
    <body>
        //Here i have various html elements and i want to play with these elements using PHPQuery.
    </body>
</html>

Solution

  • It's a strange request, but you could do:

    $html = file_get_contents(__FILE__);
    $dom = phpQuery::newDocument($html);