当前文件的phpQuery

当前文件的phpQuery,php,domparser,phpquery,Php,Domparser,Phpquery,我只是想开始使用phpquerydom解析器,但我不知道如何加载当前的php文件,以便能够处理这个特定页面中的元素 假设我有一个php文件about.php。它有一个简单的标记: <?php require('phpQuery/phpQuery.php'); phpQuery::newDocument(); pq('div')->addClass('myclass'); // this doesn't work ?> <html> &

我只是想开始使用phpquerydom解析器,但我不知道如何加载当前的php文件,以便能够处理这个特定页面中的元素

假设我有一个php文件
about.php
。它有一个简单的标记:

<?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>

这是一个奇怪的请求,但您可以:

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

来吧,至少读一下文档。在的“基础知识”页面上,您可以在PHPSupport页面上阅读更多关于它的信息。我不介意使用否定标记。在发布问题之前,我已经尝试过了。下面是通过在第3行告诉未定义变量:D:\xampp\htdocs\phpQuery\index.php中的html的方式得到的结果,这就是我的问题所说的。如何将当前文件html转换为$html