获取url中部份内容代码

  1. function getpath($url)
  2. {
  3. $path = parse_url($url,php_url_path);
  4. $lastslash = strrpos($path,"/");
  5. return substr($path,1,$lastslash-1);
  6. }
  7. echo getpath("http://www.phpfensi.com/blog/entry-title/?standalone=1");
  8. //
  9. function getpathurl() {
  10. $folder = explode('/', $_server['script_name']);
  11. $script_filename = pathinfo($_server['script_name']);
  12. $request = explode('/', $_server['request_uri']);
  13. array_shift($folder);
  14. array_shift($request);
  15. $final_request = array_diff($request, array_intersect($folder, $request));
  16. $final_request = array_values($final_request);
  17. array_clean($final_request);
  18. $final_request = implode('/', $final_request);
  19. if ($_server['query_string'] || substr($final_request, -1) == '?') {
  20. $final_request = substr($final_request, 0, - strlen($_server['query_string']) - 1);
  21. }
  22. return $final_request;
  23. }