3v4l.org

run code in 300+ PHP versions simultaneously
<?php function parsePrice(string $price): int { // 0 - рубли, 1 - копейки $price = trim(str_replace(['руб.', ' ',], ['', ''], $price)); $price = str_replace(',', '.', $price); $priceExp = []; $amount = 0; if (str_contains($price, '.')) { $priceExp = explode('.', $price); $amount = (int) str_pad(substr($priceExp[1], 0, 2), 2, '0'); } return (int) ($priceExp[0] ?? $price) * 100 + $amount; } print parsePrice('0');
Output for 8.2.0 - 8.2.28, 8.3.0 - 8.3.21, 8.4.1 - 8.4.7
0

preferences:
44.15 ms | 406 KiB | 5 Q