我不知道 PHPQuery,但在 StackOverflow 上获取它的文档、您的 jQuery 代码和一些已经存在的 phpQuery 问题,这个应该可以工作。
$experiments = pq('.experiment');
foreach($experiments as $experiment){
echo "Experiment: ". $experiment->find('.experiment-number')->text();
echo "Experiment ULs: " + $experiment->find('ul')->size();
$total = 0;
foreach($experiment->find('ul.data-values li') as $t){
$total += (int) $t;
}
echo "Experiment total: " . $total;
}
编辑(说真的,你应该看到的只有 3 个错误):
$experiments = pq('.experiment');
foreach($experiments as $experiment){
$experiment = pq($experiment);
echo "Experiment: ". $experiment->find('.experiment-number')->text();
echo "Experiment ULs: " . $experiment->find('ul')->size();
$total = 0;
foreach($experiment->find('ul.data-values li') as $t){
$t = pq($t);
$total += (int) $t->text();
}
echo "Experiment total: " . $total;
}
- a
+
变成 a .
(我在复制你的 jQuery 代码时犯了一个错误)
- 您在评论中指出的那个。
(int) $t->text();