我需要使用php显示行的数量(tr),但我不知道如何执行此操作,因为我使用的是引号。
$data['formation'] = '
<div class="table-responsive">
<table class="table table-bordered" style="width: auto !important;">
<thead style="font-weight: bold;">
<tr>
<td>N</td>
<td>Intitulé</td>
<td>Organisme</td>
<td>Date</td>
<td>Durée (en heures)</td>
<td>Eval. à chaud / à froid</td>
<td>Dispositif utilisé</td>
</tr>
</thead>
<tbody class="table-striped">
<tr>
<td>
**HERE NUM OF THE ROW**
</td>
<td>
<input type="text" class="form-control" name="form_intitule" id="form_intitule" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_organisme" id="form_organisme" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_date" id="form_date" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_duree" id="form_duree" readonly>
</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>';
}
这是我的代码:
foreach($html->find('table') as $table){
// returns all the <tr> tag inside $table $all_trs = $table->find('tr');
$count = count($all_trs); echo $count;
}
答案 0 :(得分:0)
试试这个:
$count = substr_count($data['formation'], "<tr>");
echo "Total rows: ".$count;
答案 1 :(得分:0)
虽然它不是一个好的解决方案,但仍然易于使用。您可以使用substr_count
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
var shouldIAllow = false
switch status {
case CLAuthorizationStatus.Restricted:
locationStatus = "Restricted Access to location"
case CLAuthorizationStatus.Denied:
locationStatus = "User denied access to location"
case CLAuthorizationStatus.NotDetermined:
locationStatus = "Status not determined"
default:
locationStatus = "Allowed to location Access"
shouldIAllow = true
}
if (shouldIAllow == true) {
print("Location to Allowed")
// Start location services
locationManager!.startUpdatingLocation()
} else {
print("Denied access: \(locationStatus)")
NSNotificationCenter.defaultCenter().postNotificationName("deniedLocation", object:locationStatus)
}
}
答案 2 :(得分:0)
这是一种解决方法。但它的效果也一样。
echo substr_count($data['formation'], '<tr>'); // 2
上述代码的作用是计算print_r(array_count_values(str_word_count($data['formation'], 1)) );
字符串中的所有单词。然后,它会将其分组并将结果放入数组中。
然后它将打印数组,您可以看到$data['formation']
出现的次数。