Answer the question
In order to leave comments, you need to log in
How to write a regular expression correctly?
Here is my code:
$table = '
<tr>
<td valign="bottom" width="120"><p align="center">7</p></td>
<td valign="bottom" width="20"><p align="center">40</p></td>
</tr>
<tr>
<td valign="bottom" width="120"><p align="center">6,7</p></td>
<td valign="bottom" width="20"><p align="center">67,9</p></td>
</tr>';
$pattern = '/<p align="center">(.+?)<\/p>/';
preg_match_all($pattern, $table, $arr);
foreach($arr as $val){
var_dump($val);
}
array(4) { [0]=> string(1) "7" [1]=> string(2) "40" [2]=> string(3) "6,7" [3]=> string(4) "67,9" }
array(4) {
array(1){ [0]=> string(1) "7" [1]=> string(2) "40" }
array(2){ [0]=> string(3) "6,7" [1]=> string(4) "67,9" }
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question