fork download
  1. <?php
  2.  
  3.  
  4. $regexp = '!^htt(p|ps)://([^\s]+){3}$|(^$)!';
  5.  
  6. $correctNumber = array(
  7. 'http://wt_import(filename)',
  8. 'https://1232145',
  9. 'http://eom',
  10. 'https://content-available-to-author-only.html#465723',
  11. '',
  12. );
  13.  
  14. $wrongNumber = array(
  15. 'http://example com with many spaces',
  16. ' https://2...content-available-to-author-only.....contenttml#465723',
  17. 'http, http://, example.com',
  18. 'http://ex',
  19. 'http://',
  20. 'l',
  21. ' http:// ',
  22. 'https:// ',
  23. 'https:// DF',
  24. ' ',
  25. ' ',
  26. ' ',
  27. ' ',
  28. ' ',
  29. ' ',
  30. ' ',
  31. ' ',
  32. ' ',
  33. ' ',
  34. ' sdfsdf ',
  35. 'sdfsdf sdfsdf ',
  36. 'qeqweqw',
  37. ' ',
  38. );
  39.  
  40. echo "TRUE\n\n";
  41.  
  42. foreach ($correctNumber as $number) {
  43. if (preg_match($regexp, $number)) {
  44. echo "[+] \"{$number}\"\n";
  45. } else {
  46. echo "[-] \"{$number}\"\n";
  47. }
  48. }
  49.  
  50. echo "\nFALSE\n\n";
  51.  
  52. foreach ($wrongNumber as $number) {
  53. if (preg_match($regexp, $number)) {
  54. echo "[+] \"{$number}\"\n";
  55. } else {
  56. echo "[-] \"{$number}\"\n";
  57. }
  58. }
  59.  
Success #stdin #stdout 0.02s 24144KB
stdin
Standard input is empty
stdout
TRUE

[+] "http://wt_import(filename)"
[+] "https://1232145"
[+] "http://eom"
[+] "https://content-available-to-author-only.html#465723"
[+] ""

FALSE

[-] "http://example com with     many spaces"
[-] " https://2...content-available-to-author-only.....contenttml#465723"
[-] "http, http://, example.com"
[-] "http://ex"
[-] "http://"
[-] "l"
[-] " http:// "
[-] "https:// "
[-] "https:// DF"
[-] " "
[-] "  "
[-] "  "
[-] "   "
[-] "    "
[-] "     "
[-] "      "
[-] "       "
[-] "          "
[-] "            "
[-] "      sdfsdf      "
[-] "sdfsdf      sdfsdf      "
[-] "qeqweqw"
[-] "            "