按名称获取表单


Get form by name

如何使用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");

使用这个...

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

源。

>phpQuery支持与选择器相同的CSS/jQuery,所以这就是你想要的:

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

注意:同时将$pq->find更改为pq

例:

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

结果:

Something

在您的情况下,它将返回表单的 html。