php - Add 15% to price between brackets in string using preg_replace -
i have strings need find number between < > brackets, found post on stack overflow , trying use code found there
$colops = preg_replace_callback( '/\<(\d+)\>/', function( $match) { return '<' . ($match[1] * 1.15) . '>'; }, $row_products['colops']); my strings
no storage<118.54>, storage 2 drawer<158.54>,storage slider<138.54>
am doing right, there better way this?
\d match digits. seems need match dots in order catch things 118.54.
your expression should more this:
$colops = preg_replace_callback('/\<([\d.,]+)\>/', function($match) { return '<' . number_format(floatval($match[1]) * 1.15, 2) . '>'; }, $row_products['colops']);
Comments
Post a Comment