I’ve tried learning this but for whatever reason it just does not work.
I have the following:
text here:
5.3 x 6.0 x 40 metres
which in code is:
<li><b>
text here:
</b>
5.3 x 6.0 x 40 metres
</li>
This HTML is in a variable let’s call it $dimensions
I’m trying to extract the 5.3 x 6.0 x 40 metres with a preg_match_all, ideally extracting the dimensions and also the measurement but I’m having trouble echoing the results. It says array conversion to string error each time despite the size of matches being 5. Any Ideas what’s going on?
preg_match_all('/\<li\>([0-9]*\.*[0-9]*)x([0-9]*\.*[0-9]*)x([0-9]*\.*[0-9]*)
\s*([a-zA-Z]*)\<\/li\>/',$dimensions,$matches,PREG_PATTERN_ORDER);
echo sizeof($matches);
echo($matches[0]);
EDIT:
As suggested by an answer below: someone said use var_dump($matches) to see what the array contains…
Turns out I have 4 empty arrays, which brings up the next question. what is wrong with my preg_match_all?
array (size=5)
0 =>
array (size=0)
empty
1 =>
array (size=0)
empty
2 =>
array (size=0)
empty
3 =>
array (size=0)
empty
4 =>
array (size=0)
empty
I would suggest dont use pregmatch first for such purposes and use html
DOMdocumentand query the nodes with XPath, limit the result to text itself and then use preg_match_allThe above will get you the numerical value of each dimension