3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "description: test1: 10 €, test2: 7.50 €, test3: 25%, test4: 30%"; $levelamt = 0.75; $description = preg_replace_callback('/([0-9][.0-9]*)\s*(\s€|%)/i', function($matches) use ($levelamt){ return round(($matches[1] * $levelamt),2).$matches[2]; }, $string); echo $description;

preferences:
138.29 ms | 1935 KiB | 5 Q