Advertisement
Guest User

Untitled

a guest
Jan 27th, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. http://www.yoursite.com/offers/838?&SITEID=2172
  2.  
  3. http://www.yoursite.com/offers/838
  4.  
  5. $str = 'http://www.yoursite.com/offers/838?&SITEID=2172';
  6.  
  7. function remove_query_arg($var, $url = NULL){
  8. if(!$url){
  9. $url = $_SERVER['REQUEST_URI'];
  10. }
  11. $parsed_url = parse_url($url);
  12.  
  13. $query_vars = explode('&', $parsed_url['query']);
  14.  
  15.  
  16. foreach($query_vars as $key => $value){
  17. $query_vars[$key] = explode('=', $query_vars[$key]);
  18. $query_variables[$query_vars[$key][0]] = $query_vars[$key][1];
  19. }
  20.  
  21. if(is_array($var)){
  22. foreach($var as $value){
  23. unset($query_variables[$value]);
  24. }
  25. }
  26. elseif(is_string($var)){
  27. unset($query_variables[$var]);
  28. }
  29.  
  30. $query_vars = array();
  31.  
  32. foreach($query_variables as $key => $value){
  33. $query_vars[] = $key.($value !== NULL || !empty($value) ? '='.$value : '');
  34. }
  35. $query_str = '';
  36. $query_str = implode('&',$query_vars);
  37.  
  38. return (isset($parsed_url['scheme']) && !empty($parsed_url['scheme']) ? $parsed_url['scheme'].'://' : '').$parsed_url['host'].(isset($parsed_url['path']) && !empty($parsed_url['path']) ? $parsed_url['path'] : '').(!empty($query_str) ? '?'.$query_str : '');
  39. }
  40.  
  41. echo remove_query_arg('SITEID', $str);
  42.  
  43. $url = "http://www.yoursite.com/offers/838?&SITEID=2172";
  44. $parts = parse_url($url);
  45.  
  46. $url = $parts["scheme"] . "://" . $parts["host"] . $parts["path"];
  47.  
  48. $url=http://www.yoursite.com/offers/838?&SITEID=2172
  49. $result=explode('?',$url)
  50. print_r($result);
  51.  
  52. array
  53. {
  54. [0]=>http://www.yoursite.com/offers/838
  55. [1]=>?&SITEID=2172
  56. }
  57.  
  58. $url = "http://www.yoursite.com/offers/838?&SITEID=2172";
  59. list($path, $query) = explode("?", $url, "2");
  60. var_dump($path);
  61.  
  62. string 'http://www.yoursite.com/offers/838' (length=34)
  63.  
  64. $url = "http://www.yoursite.com/offers/838?&SITEID=2172";
  65. $str = substr($url, strpos($url, 0, "?&SITEID"));
  66. // $str results in "http://www.yoursite.com/offers/838"
  67.  
  68. ^(.+?)(?&SITEID|$)
  69.  
  70. $1
  71.  
  72. &?SITEID=[^&s]+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement