PHP Removing part of a dynamic string

Associate
Joined
26 Jun 2003
Posts
1,140
Location
North West
I have strings like this (URL):

?p1=users&p2=management&orderby=dateregistered&order=DESC&p=2

or

?p1=users&p2=management&p=2&orderby=dateregistered&order=DESC

How would I elimate certain variables from this? such as p?

I need to remove &p=2 (the number can be any number).

How can this be done?
 
Well this is the kind of thing i need to do

Code:
$string = $_SESSION['QUERY_STRING'];

$string = removeP($string);

echo '<a href="'.$string.'">Link</a>'
 
Last edited:
Dj_Jestar said:
Code:
$string = preg_replace('/' . preg_quote('&p=', '/') . '\d+/', '', $string);

untested.

That works fine at the moment, cant see any bugs. Im not sure what that preg_quote is doing tho.
 
joeyjojo said:
Not sure. Looks like it would only replace '&p=' with ''.

What does the \d+/ do? All those slashes are confusing.

Yeh whats is that d+?

What what I have to change if instead of numbers after the p there was letters?
 
Back
Top Bottom