如果我理解得很好,这是您的 html 代码和课程详细信息的示例:
<?php
$subject = <<<'LOD'
<tr class="main_row pc">
<td class="details">
<div class="attribs">
Αγροτικό/Pickup
2500cc,
102bhp,
Manual,
Πετρέλαιο,
Ασπρο,
</div>
</td>
<td class="registration">9 / 95</td>
<td class="mileage">151.000</td>
<td class="price">
<span class="p_p">€ 6.300</span>
</td>
</tr>
<tr class="main_row pc">
<td class="details">
<div class="attribs">
Λιμουζίνα/Sedan
1800cc,
Manual,
Βενζίνη,
Γαλάζιο,
</div>
</td>
<td class="registration">3 / 00</td>
<td class="mileage">0</td>
<td class="price">
<span class="p_p">€ 900</span>
</td>
</tr>
<tr class="main_row pc">
<td class="details">
<div class="attribs">
Αγροτικό/Pickup
2400cc,
1bhp,
Manual,
Πετρέλαιο,
Κόκκινο,
</div>
</td>
<td class="registration">1 / 95</td>
<td class="mileage">1</td>
<td class="price">
<span class="p_p">€ 2.650</span>
</td>
</tr>
LOD;
$pattern = <<<'LOD'
~
<td \s* class="details">\s*
(?>
(?> [^0-9<]++ | [0-9](?![0-9]{0,3}bhp) | <(?!/td>) )* \K
[0-9]{1,4}bhp
|
\K (?> [^<]++ | <(?!/td>) )*
)
~ix
LOD;
preg_match_all($pattern, $subject, $matches);
print_r($matches);