3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input="1234567890"; function format_phone_number($input) { $stripped = preg_replace('/[^0-9]/', '', $input); $len = strlen($stripped); if ($len === 10) { return '1' . $stripped; } if ($len === 11 && $stripped[0] === '1') { return $stripped; } } function validate_phone_number($input) { if (format_phone_number($input) == 11) { return true; } else { return false; } } if (validate_phone_number($input)) { echo "valid"; }; ?>
Output for 5.6.0 - 5.6.26, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3

preferences:
100.15 ms | 1672 KiB | 4 Q