Does any one have a simple method of cropping off / removing HTTP queries from a URL?
In example I may have...
example.php?my_query
...and I'd want to change it to...
example.php
Crop/remove HTTP query from end of a URL?
Moderator: General Moderators
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Crop/remove HTTP query from end of a URL?
If you want just the filename without the query string,
If you want to simply remove the query string, and keep the rest of your url, i.e. http://foo.com/page.php?foo, then simply
Code: Select all
$basename = array_shift(explode('?', basename($url)));Code: Select all
$basename = array_shift(explode('?', $url));- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: Crop/remove HTTP query from end of a URL?
Yes, I was thinking that after I posted. That was pretty quick!
Is this technically regex?
What about this...?
I can't use string positioning because the url length will always vary though I know that if at all possible I should avoid regex.
What about this...?
Code: Select all
echo strtok('example.php?my_query','?');- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Crop/remove HTTP query from end of a URL?
No it is not regex. Simple string manipulation.JAB Creations wrote:Yes, I was thinking that after I posted. That was pretty quick!Is this technically regex?
What about this...?I can't use string positioning because the url length will always vary though I know that if at all possible I should avoid regex.Code: Select all
echo strtok('example.php?my_query','?');
strtok() essentially the same as explode(), and I also find it more readable.