3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $rows = [ ['`1234567890-=', '~!@#$%^&*()_+'], ['qwertyuiop[]\\', 'QWERTYUIOP{}|'], ['asdfghjkl;\'', 'ASDFGHJKL:"'], ['zxcvbnm,./', 'ZXCVBNM<>?'] ]; $wholeregex = []; foreach($rows as $k => $row) { $num = $k + 1; echo "Row $num\n"; $array = []; foreach($row as $subrow) { $subarray = array_map('ord', str_split($subrow)); $array = array_merge($subarray, $array); } sort($array); echo "\t" . implode( ' ', $array), "\n"; $ret = [$array[0]]; for($i = 1; $i < count($array); $i++) { $num = $array[$i]; if(($array[$i - 1] + 1) == $num) { if( ($i == (count($array) - 1)) || ($array[$i + 1] != ($num + 1)) ) { $ret[] = array_pop($ret) . '-' . $num; } } else { $ret[] = $num; } } echo "\t" . implode( ' ', $ret), "\n"; $regex = '(['; $subregex = implode( '', array_map(function($el) { $vals = explode('-', $el); if(count($vals) == 1) { return chr($vals[0]); } return chr($vals[0]) . '-' . chr($vals[1]); }, $ret)); $regex .= $subregex; $regex .= '])'; echo "\t" . $regex, "\n"; $wholeregex[] = $regex; } $finalregex = '%' . implode('|', $wholeregex) . '%'; $finalregex = str_replace('(-', '\(-', $finalregex); echo $finalregex, "\n"; echo strlen($finalregex), "\n"; $argv[1] = "a"; $i=$argv[1];preg_match("%([!#-&\(-+-0-9=@^-`~])|([EIO-RT-UWY[-]eio-rt-uwy{-}])|(["':-;ADF-HJ-LSadf-hj-ls])|([,.-/<>-?B-CM-NVXZb-cm-nvxz])%",$i,$m);echo array_flip($m)[$i];
based on ZXs6M
Output for 7.0.0 - 7.0.2
Parse error: syntax error, unexpected '':-;ADF-HJ-LSadf-hj-ls])|([,.-' (T_ENCAPSED_AND_WHITESPACE), expecting ',' or ')' in /in/cP7IT on line 59
Process exited with code 255.
Output for 5.4.11 - 5.6.17
Parse error: syntax error, unexpected '':-;ADF-HJ-LSadf-hj-ls])|([,.-' (T_ENCAPSED_AND_WHITESPACE) in /in/cP7IT on line 59
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/cP7IT on line 2
Process exited with code 255.