2012-06-27 125 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。