I need to display the num of the row (tr) using php, but I don't know how to do this because I am using quotes.
$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>';
}
This is my code:
foreach($html->find('table') as $table){
// returns all the <tr> tag inside $table $all_trs = $table->find('tr');
$count = count($all_trs); echo $count;
}
Try this:
$count = substr_count($data['formation'], "<tr>");
echo "Total rows: ".$count;
Though it's not a good solution but still simple to use. You can use substr_count
echo substr_count($data['formation'], '<tr>'); // 2
This is a bit of a workaround. But it works just as well.
print_r(array_count_values(str_word_count($data['formation'], 1)) );
What the above code does is count all words in the $data['formation']
string. Then, it will devide this into groups and put the results in an array.
It will then print the array and you can see how much times <tr>
occurs.