How to remove GET-variables with PHP?

0 votes

I have a string with a full URL including GET variables. Which is the best way to remove the GET variables? Is there a nice way to remove just one of them?

This is a code that works but is not very beautiful (I think):

$current_url = explode('?', $current_url);
echo $current_url[0];

The code above just removes all the GET variables. The URL is in my case generated from a CMS so I don't need any information about server variables.

Oct 27 in PHP by kartik
• 35,300 points
27 views

1 answer to this question.

0 votes

Hello @kartik,

Try this:

preg_replace('/\\?.*/', '', $str)

Hope it works!!

answered Oct 27 by Niroj
• 76,540 points

Related Questions In PHP

0 votes
1 answer

How to Validate Form Data With PHP?

Hey @kartik, The first thing we will do ...READ MORE

answered Feb 13 in PHP by Niroj
• 76,540 points
278 views
0 votes
1 answer

What is a Cookie? How to create Cookies With PHP?

A cookie is often used to identify ...READ MORE

answered Feb 13 in PHP by Niroj
• 76,540 points
479 views
0 votes
1 answer

How to prevent XSS with HTML/PHP?

Hello, HTML Encoding htmlspecialchars will convert any "HTML special characters" ...READ MORE

answered Apr 1 in PHP by Niroj
• 76,540 points
187 views
0 votes
1 answer

How to get the client IP address in PHP ?

Hello, Here is a code sample of a good ...READ MORE

answered Apr 8 in PHP by Niroj
• 76,540 points
1,897 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 76,540 points
3,435 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18 in Laravel by Niroj
• 76,540 points
411 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23 in Laravel by Niroj
• 76,540 points
281 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23 in Laravel by Niroj
• 76,540 points
4,140 views
0 votes
1 answer

How to get original URL referer with PHP?

Hello @kartik, Store it either in a cookie or ...READ MORE

answered Sep 1 in PHP by Niroj
• 76,540 points
614 views
0 votes
1 answer

How to remove a child with a specific attribute, in SimpleXML for PHP?

Hii, Just unset the node: $str = <<<STR <a> ...READ MORE

answered Nov 5 in PHP by Niroj
• 76,540 points
10 views