3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $string = '+1 (214) 662-2590'; $pattern = '/^[0-9,+]+$/i'; $strlen = strlen($string); $iterations = pow(2, $strlen); for ($i = 0; $i < $iterations; $i++) { $tmp_string = $string; $number = $i; $k = 1; while ($number) { if ($number % 2) $tmp_string = substr_replace($tmp_string, '', $strlen - $k, 1); $number = (int) ($number / 2); $k++; } if (preg_match($pattern, $tmp_string)) { var_dump($tmp_string); break; } }
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
string(12) "+12146622590"