fork(5) download
  1. <?php
  2.  
  3. function removeQueryStringFromUrl($url) {
  4. if (substr($url,0,4) == "http") {
  5. $urlPartsArray = parse_url($url);
  6. $outputUrl = $urlPartsArray['scheme'] . '://' . $urlPartsArray['host'] . ( isset($urlPartsArray['path']) ? $urlPartsArray['path'] : '' );
  7. } else {
  8. $URLexploded = explode("?", $url, 2);
  9. $outputUrl = $URLexploded[0];
  10. }
  11. return $outputUrl;
  12. }
  13.  
  14. echo removeQueryStringFromUrl("http://www.google.com/myfolder/")."\n";
  15. echo removeQueryStringFromUrl("http://www.google.com/myfolder/?aaa=1")."\n";
  16. echo removeQueryStringFromUrl("http://www.google.com/myfolder/?aaa=1&bbbb=1")."\n";
  17.  
  18. echo removeQueryStringFromUrl("/myfolder/")."\n";
  19. echo removeQueryStringFromUrl("/myfolder/?aaa=1")."\n";
  20. echo removeQueryStringFromUrl("/myfolder/?aaa=1&bbbb=1")."\n";
  21.  
  22. echo removeQueryStringFromUrl("https://www.google.com/myfolder/")."\n";
  23. echo removeQueryStringFromUrl("https://www.google.com/myfolder/?aaa=1")."\n";
  24. echo removeQueryStringFromUrl("https://www.google.com/myfolder/?aaa=1&bbbb=1")."\n";
  25.  
  26. // your code goes here
Success #stdin #stdout 0.02s 24400KB
stdin
Standard input is empty
stdout
http://www.google.com/myfolder/
http://www.google.com/myfolder/
http://www.google.com/myfolder/
/myfolder/
/myfolder/
/myfolder/
https://www.google.com/myfolder/
https://www.google.com/myfolder/
https://www.google.com/myfolder/