2012-06-27 126 views
0

如何使用phpQuery获取具有特定名称的表单?按名称获取表格

<form method="POST" name="example"> 
     <input type="hidden" 
... 

我尝试:

include 'phpQuery-onefile.php'; 
//example site with this form 
$html = file_get_contents("http://www.example.com"); 

$pq = phpQuery::newDocument($html); 
$a = $pq->find("form name=example"); 

回答

2

使用此...

$a = $pq->find("form[name=example]"); 

Source

2

phpQuery支持相同CSS/jQuery的喜欢选择,所以这是你想要什么:

$a = pq("form[name=example]"); 

注:也改变$pq->findpq

例子:

phpQuery::newDocumentHTML('<form method="POST" name="example">Something</form>'); 
$a = pq("form[name=example]"); 
echo $a; 

结果:

Something 

在你的情况下通过,它将返回表单的HTML。