PHP脚本中使用HTML div的总次数?
我采访了40多人,我想用一个PHP脚本来说明这一点 当然,每个面试都有自己的CSS类,我可以很容易地添加一个额外的类或使用现有的类来发现div的总数 下面是一个面试的例子:PHP脚本中使用HTML div的总次数?,php,css,html,Php,Css,Html,我采访了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="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>
A.N.其他
智能分析硕士生
面试问答在这里进行
2017年6月
我正在考虑使用类似于PHP substr_count()函数的东西来实现这个
所有面试都在一个静态HTML页面上
有人能为我指出正确的方向吗
谢谢 我会将信息保存在一个数组中,这样你就可以进行
sizeof
并获得你所做的采访的数量
你应该如何储存面试
你应该如何展示面试
如何显示面试的计数
为什么不能使用PHP计算静态HTML
PHP是服务器呈现的。因此,如果你要计算采访的数量,那么基本上你应该在呈现内容之前抓取页面本身,这是可能的,但这将是一团混乱。如果您坚持将内容保持为静态HTML,那么我建议使用JavaScript来计算元素的数量——例如,为面试的所有外部容器提供一个类,然后做一些事情。PHP不适合这种情况 因为您使用的是HTML,并且HTML已经在DOM中,所以您需要使用客户端(javascript)而不是服务器端语言来完成这项工作。如果每个人都有分配给他们的
简历项目
类别,请使用javascript对每个类别进行计数
//获取所有简历项div的总数
count=document.querySelectorAll('.resume item')。长度;
//将该总数插入总数div
document.getElementById('total-count')。innerHTML=count代码>
A.N.其他
智能分析硕士生
面试问答在这里进行
2017年6月
A.N.其他
智能分析硕士生
面试问答在这里进行
2017年6月
substr\u计数似乎很完美,有什么问题吗?Javascript最适合这样做@谢谢,谢谢。我会把jsfifle放在脚本标记中吗?谢谢,我已经更新了JSFIDLE。只需将javascript部分中的内容添加到脚本标记中,然后
显示总数的任何位置。如果这对你有效,我可以给你一个答案。解析错误:语法错误,意外的“$subheading”(T_变量),在第5行的/home/site/public_html/test.php中应为“]>,我尝试了双引号,但没有乐趣…知道缺少什么吗?谢谢你,-听起来你好像在试图访问$subheading
,而实际上应该是$interview['subheading']
。啊,等等。我忘了在我的解决方案中有逗号。我刚刚纠正了这一点。如果你复制粘贴代码,那么它应该可以工作。你是怎么做到的?
<?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 );
?>