php regex I need extract certain data from a string
Even though this is not a regexp-based idea, you could solve your problem by splitting your string based on " " and then observing where you have text, in which case on the left and right edge you have numbers that go with that text. Something like this:
$texts[0], "b" => $texts[1]];
}
$arr = splitMyText($str);
foreach ($arr as $key => $el) {
var_export($el);
}
and then you can use it as
list($a, $b) = splitMyText("");
array (
0 => '3.30',
1 => '2.20',
2 => '2.10',
3 => '3.80',
4 => '2.40',
5 => '2.10',
)array (
0 => '$1.00 six years ago 5.80',
1 => '$0.10 today is 1.52',
2 => '$0.50 now 4.45',
)
Read more here: Source link
