-1

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>
6
  • C'mon, at least read the documentation. The "Basics" page at code.google.com/p/phpquery/wiki/Basics says you'd do phpQuery::newDocumentPHP($html, $contentType = null) Read more about it on PHPSupport page. Commented Nov 1, 2014 at 23:45
  • I won't mind getting negative marking. Commented Nov 1, 2014 at 23:45
  • i have tried this before posting the question. Here is what i get by doing the way you told Undefined variable: html in D:\xampp\htdocs\phpQuery\index.php on line 3 Commented Nov 1, 2014 at 23:46
  • 1
    That is what my question says. How would i get the current file html to $html Commented Nov 1, 2014 at 23:48
  • 1
    php.net/file_get_contents Commented Nov 1, 2014 at 23:49

1 Answer 1

1

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

$html = file_get_contents(__FILE__);
$dom = phpQuery::newDocument($html);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.