I have some strings that I need to find the number between the < > brackets, I found a post on stack overflow and I am trying to use the code I found there
$colops = preg_replace_callback( '/\<(\d+)\>/', function( $match) {
return '<' . ($match[1] * 1.15) . '>';
}, $row_products['colops']);
My strings look like this
No Storage<118.54>, Storage 2 Drawer<158.54>,Storage with Slider<138.54>
Am I doing this right, is there a better way to do this?
\d
will match only digits. It seems you need to match dots too in order to catch things like 118.54
.
Your expression should be something more like this:
$colops = preg_replace_callback('/\<([\d.,]+)\>/', function($match) {
return '<' . number_format(floatval($match[1]) * 1.15, 2) . '>';
}, $row_products['colops']);