-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>
MarthyM
  • 1,839
  • 2
  • 21
  • 23
Raheel
  • 8,716
  • 9
  • 60
  • 102
  • C'mon, at least read the documentation. The "Basics" page at https://code.google.com/p/phpquery/wiki/Basics says you'd do `phpQuery::newDocumentPHP($html, $contentType = null) Read more about it on PHPSupport page`. – ceejayoz Nov 01 '14 at 23:45
  • I won't mind getting negative marking. – Raheel Nov 01 '14 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 – Raheel Nov 01 '14 at 23:46
  • Well, did you load the PHP file's contents into `$html`? You can't just randomly copy/paste others' code without understanding anything about it. – ceejayoz Nov 01 '14 at 23:48
  • 1
    That is what my question says. How would i get the current file html to $html – Raheel Nov 01 '14 at 23:48
  • 1
    http://php.net/file_get_contents – ceejayoz Nov 01 '14 at 23:49

1 Answers1

1

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

$html = file_get_contents(__FILE__);
$dom = phpQuery::newDocument($html);
pguardiario
  • 53,827
  • 19
  • 119
  • 159