当前文件的phpQuery
问题描述:
我只是试图开始使用phpQuery的DOM解析器,但我不明白如何加载当前的PHP文件,以便我可以玩这个特定页面中的元素。当前文件的phpQuery
说我有一个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);
+0
非常感谢你 – 2014-11-02 20:28:13
来吧,至少阅读文档。 https://code.google.com/p/phpquery/wiki/Basics上的“基本信息”页面显示您可以执行phpQuery :: newDocumentPHP($ html,$ contentType = null)在PHPSupport页面上阅读更多关于它的信息。 – ceejayoz 2014-11-01 23:45:27
我不介意让负面的标记。 – 2014-11-01 23:45:39
我在发布问题之前已经尝试过。这是我按照你告诉的方式得到的 未定义的变量:第3行D:\ xampp \ htdocs \ phpQuery \ index.php中的html – 2014-11-01 23:46:52