Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strip off URL parameter with PHP

Tags:

php

I have some links in a powerpoint presentation, and for some reason, when those links get clicked, it adds a return parameter to the URL. Well, that return parameter is causing my Joomla site's MVC pattern to get bungled.

So, what's an efficient way to strip off this return parameter using PHP...?

Example: http://mydomain.com/index.php?id=115&Itemid=283&return=aHR0cDovL2NvbW11bml0

like image 894
tpow Avatar asked Feb 08 '11 19:02

tpow


People also ask

How to remove specific query string from url?

To remove a querystring from a url, use the split() method to split the string on a question mark and access the array element at index 0 , e.g. url. split('? ')[0] . The split method will return an array containing 2 substrings, where the first element is the url before the querystring.


1 Answers

The safest "correct" method would be:

  1. Parse the url into an array with parse_url()
  2. Extract the query portion, decompose that into an array using parse_str()
  3. Delete the query parameters you want by unset() them from the array
  4. Rebuild the original url using http_build_query()

Quick and dirty is to use a string search/replace and/or regex to kill off the value.

like image 95
Marc B Avatar answered Sep 18 '22 14:09

Marc B