fork download
  1. <?php
  2.  
  3. $ss = ["8.8.8.8|0", "8.8.8.8|1", "8.8.8.8|65536", "8.8.8.8|dawda"];
  4. foreach ($ss as $s) {
  5. if (preg_match('~^\d+(?:\.\d+){3}\|(.*)$~', $s, $res)) {
  6. if (ctype_digit($res[1]) && intval($res[1]) > 0 && intval($res[1]) < 65536 ) { // valid port, omit
  7. echo "The port is valid: " . $res[1] . "\n";
  8. } else {
  9. echo "Invalid port: " . $res[1] . "\n";
  10. }
  11. }
  12. }
Success #stdin #stdout 0s 82944KB
stdin
Standard input is empty
stdout
Invalid port: 0
The port is valid: 1
Invalid port: 65536
Invalid port: dawda