3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function validateSenderName ($check) { $sender = array_shift($check); echo "Is $sender numeric?\n"; var_dump(is_numeric($sender)); if(is_numeric($sender)) { $valid = preg_match('/[0-9]{7,15}/', $sender); } else { $valid = preg_match('/[0-9a-z\-_\.&#\!]{3-11}/i', $sender); } return $valid; } //should all return true: var_dump(validateSenderName(['foo' => '0123456789012345'])); // 15 numbers var_dump(validateSenderName(['foo' => 'ABCDEFGHIJK'])); // 11 characters var_dump(validateSenderName(['foo' => '01234567'])); //7 numbers var_dump(validateSenderName(['foo' => 'ABC'])); //3 characters var_dump(validateSenderName(['foo' => '1ABC'])); //4 characters echo "--\n"; //should all return false: var_dump(validateSenderName(['foo' => 'ABCDEFGHIJKL'])); //12 chracters var_dump(validateSenderName(['foo' => '012345'])); //5 numbers var_dump(validateSenderName(['foo' => 'AB'])); //2 chracters var_dump(validateSenderName(['foo' => '01234567890123456'])); //16 numbers
based on Yj8Xg
Output for 5.4.0 - 7.2.0
Is 0123456789012345 numeric? bool(true) int(1) Is ABCDEFGHIJK numeric? bool(false) int(0) Is 01234567 numeric? bool(true) int(1) Is ABC numeric? bool(false) int(0) Is 1ABC numeric? bool(false) int(0) -- Is ABCDEFGHIJKL numeric? bool(false) int(0) Is 012345 numeric? bool(true) int(0) Is AB numeric? bool(false) int(0) Is 01234567890123456 numeric? bool(true) int(1)
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/pqumn on line 22
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[', expecting ')' in /in/pqumn on line 22
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/pqumn on line 22
Process exited with code 255.