【发布时间】:2014-04-03 13:04:26
【问题描述】:
我目前正在使用此代码来检索标签。
$title = $pq->find("title")->text();
$h1 = $pq->find("h1")->text();
$p = $pq->find("p")->text();
这是正确的做法吗?
其次,我必须查看我的数组 $array_words 中的哪个单词在哪个标签中。所以我检索了file_get_contents 并删除了所有标签并将所有单词放入一个数组中。现在让我们以此为例:
Array
(
[0] => hello
[1] => there
[2] => this
[3] => is
[4] => a
[8] => test
[9] => array
)
这将是 HTML:
<html>
<head>
<title>
hello there
</title>
</head>
<body>
<h1>
this is a
</h1>
<p>
test array
</p>
</body>
</html>
我怎样才能知道哪个词在哪个标签中找到?
我希望我能说明我想要做什么。
【问题讨论】:
-
你在使用什么库,或者你在 $pq 变量中实例化了女巫类?
-
@MauricioPiberFão
$pq = phpQuery::newDocument($file);这就是我设置$pq如果这就是你的意思=/ 库不只是php 5 吗?我是phpquery的新手,请原谅我的无知