phpQuery用于当前文件

时间:2014-11-01 23:31:18

标签: php domparser phpquery

我只是想开始使用phpQuery DOM Parser,但我不知道如何加载当前的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>

1 个答案:

答案 0 :(得分:1)

这是一个奇怪的请求,但你可以这样做:

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