我只是想开始使用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>
答案 0 :(得分:1)
这是一个奇怪的请求,但你可以这样做:
$html = file_get_contents(__FILE__);
$dom = phpQuery::newDocument($html);