I'm trying to obtain two values with php regex in this kind of strings:
bla bla bla
Measures: 10,4 cm x 9 cm.
bla bla bla
Results:
1: 10,4 (note: decimal values with comma)
2: 9
The pattern Measures: X cm x Y cm.
is always the same.
I was trying: '@^(?:Measures: )?([^.]+)@' but I can't improve it to obtain the first and second values.
Thank you very much!
Use this:
$pattern = '~Measures: ([0-9]+,*[0-9]*) cm x ([0-9]+,*[0-9]*)~';
preg_match_all($pattern, $txt, $matches);
$widths = $matches[1];
$heights = $matches[2];
if (preg_match('/Measures: (\S+) cm x (\S+) cm/', $subject, $regs)) {
$height = $regs[1];
$width = $regs[2];
}