fork download
  1. <?php
  2. function extension1() {
  3. $pathinfo = pathinfo("http://w...content-available-to-author-only...k.com/test.php?somevar");
  4. $query = $pathinfo["extension"];
  5. if (strpos($query,"?") !== false)
  6. return substr($query,0,strpos($query,"?"));
  7. return $query;
  8. }
  9. function extension2() {
  10. $strs = explode(".", 'http://w...content-available-to-author-only...k.com/test.php?somevar');
  11. $extension = array_pop($strs);
  12. $pos = strpos($extension,"?");
  13. if ($pos)
  14. $extension = substr($extension,0,$pos);
  15. return $extension;
  16. }
  17.  
  18. function extension3() {
  19. $baseName = basename('http://w...content-available-to-author-only...k.com/test.php?somevar');
  20. $dotPosition = strpos($baseName,".");
  21. $extension = substr($baseName, $dotPosition+1, strpos($baseName, "?")-$dotPosition-1);
  22. return $extension;
  23. }
  24.  
  25. function extension4() {
  26. $strs = 'http://w...content-available-to-author-only...k.com/test.php?somevar';
  27. preg_match("/\.(php)(?=\?)/", $strs ,$mathes);
  28. return $mathes[1];
  29. }
  30.  
  31. function extension5() {
  32. $path = parse_url('http://w...content-available-to-author-only...k.com/test.php?somevar');
  33. $extension = substr($path["path"], strpos($path["path"], '.')+1);
  34. return $extension;
  35. }
  36.  
  37. var_dump(extension1());
  38. var_dump(extension2());
  39. var_dump(extension3());
  40. var_dump(extension4());
  41. var_dump(extension5());
Success #stdin #stdout 0.02s 52456KB
stdin
Standard input is empty
stdout
string(3) "php"
string(3) "php"
string(3) "php"
string(3) "php"
string(3) "php"