我采访了40多人,我想用一个PHP脚本来说明这一点。
每个面试当然都有自己的一堆CSS类,我可以轻松地添加一个额外的类或使用现有类中的一个来发现div的总数。
这是面试的一个例子:
<div class="resume-item d-flex flex-column flex-md-row mb-5">
<div class="resume-content mr-auto">
<h3 class="mb-0">A.N. Other</h3>
<div class="subheading mb-3">Intelligence Analysis Masters Student</div>
<p>Interview Q&A Goes Here</p>
</div>
<div class="resume-date text-md-right">
<span class="text-primary">June 2017</span>
</div>
</div>
我正在考虑使用 PHP substr_count()函数之类的方法来实现此目标...?
所有采访都在一个静态HTML页面上。
有人可以为此指出正确的方向吗?
谢谢!
答案 0 :(得分:0)
我会将信息保存在一个数组中,因此您可以执行sizeof
并获取已完成的采访次数。
<?php
$interviews = array(
[
'title' => 'A.N. Other',
'subheading' => 'Intelligence Analysis Masters Student',
'q-and-a' => 'Interview Q&A Goes Here',
'date' => 'June 2017',
],
[
'title' => 'another entry',
'subheading' => 'blah blah blah',
'q-and-a' => 'blah blah blah',
'date' => 'blah blah blah',
],
);
?>
<?php
foreach( $interviews as $interview ):
?>
<div class="resume-item d-flex flex-column flex-md-row mb-5">
<div class="resume-content mr-auto">
<h3 class="mb-0"><?php echo $interview['title']; ?></h3>
<div class="subheading mb-3"><?php echo $interview['subheading']; ?></div>
<p><?php echo $interview['q-and-a']; ?></p>
</div>
<div class="resume-date text-md-right">
<span class="text-primary"><?php echo $interview['date']; ?></span>
</div>
</div>
<?php
endforeach;
?>
<?php
echo sizeof( $interviews );
?>
PHP是服务器渲染的。因此,如果要计算采访的数量,则基本上应该在呈现内容之前对页面本身进行爬网,这是可能的,但是那会很混乱。如果您坚持将内容保持为静态HTML,那么我建议您改用JavaScript来计算元素的数量-例如,为所有外部容器提供一个类供您进行采访,然后做一些like this 。 PHP不适合此功能。
答案 1 :(得分:0)
由于您正在使用HTML,并且HTML已经在DOM中,因此您将要使用客户端(javascript)而不是服务器端语言来执行此操作。如果每个人都有分配给他们的new AlertDialog.Builder(this)
.setTitle("Share using Wi-Fi Direct?")
.setCancelable(false)
.setMessage("You can only share folders using Wi-Fi Direct")
.setPositiveButton("SHARE VIA WI-FI DIRECT", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//do what you want here
}
})
.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//do what you want here
finish();
}
})
.create()
.show();
类,请使用javascript计数每个类。
resume-item
// Get total of all the resume-item divs
count = document.querySelectorAll('.resume-item').length;
// Insert that total in the total-count div
document.getElementById('total-count').innerHTML = count;