Having a little problem. I am trying to use preg_match_all but some how the regular expression doesn't work for one of the case.
<tr>
<td class="FieldTitle" valign="top">EAN code:</td>
<td class="Field" valign="top">3838942897078</td>
</tr>
On the above code is in variable $html
$table_html = $html;
preg_match_all("'EAN code:</td>\s*<td class=\"Field\" valign=\"top\">(.*?)</td>'si",$table_html,$extract);
$ean = $extract[1][0];
return $ean;
This returns 3838942897078. This is correct but the same code for a different scenario gives out an empty array of var_dump of $extract. Which does mean that I did not find any match.
<div class="Field"><span class="Title">Dimensions of the product (W×H×D): </span>60 × 152,4 × 64 cm</div>
The above is in $html
And the below code:
$table_html = $html;
preg_match_all("'Dimensions of the product (W×H×D):</span>(.*?)</div>'si",$table_html,$extract);
var_dump($extract);
This shows that in the dump that array is empty. Can some one throw some light on the issue. I have already tried both preg_match and preg_match_all with no luck. Help is much appreciated. Thanks in Advance
This works for me:
$table_html = $html;
preg_match_all("'Dimensions of the product \(W×H×D\): </span>(.*?)</div>'si",$table_html,$extract);
var_dump($extract);
You needed to escape the brackets around W×H×D
using a backslash \
.
As Sergey notes, you also have a </td>
in your pattern, which should be replaced with a single space to match against your HTML string.