CaptainChainsaw Posted September 8, 2008 Share Posted September 8, 2008 Hi all, I need to strip out the "pagenumber" param from the following query string: search.php?pagenumber=2¶m0=a I have a search script which is passing any seach params dynamically. So both these query strings are searching for the letter 'a'. The problem is that the pagenumber is passed around so it creates another param for it each time the "next page" link is clicked and it screws up the search. search.php?pagenumber=2¶m0=2¶m1=a Can anyone help with this one? What string functions would be best for this? Thanks in advance. CC Quote Link to comment https://forums.phpfreaks.com/topic/123283-solved-strip-out-part-of-a-string-should-be-easy-enough/ Share on other sites More sharing options...
GingerRobot Posted September 8, 2008 Share Posted September 8, 2008 parse_str()? Quote Link to comment https://forums.phpfreaks.com/topic/123283-solved-strip-out-part-of-a-string-should-be-easy-enough/#findComment-636682 Share on other sites More sharing options...
CaptainChainsaw Posted September 8, 2008 Author Share Posted September 8, 2008 I tried that function using the following code: public function removeParam($param){ parse_str($this->_querystring,$output); unset($output[$param]); return $output; } I didn't get the desired results as it still creates the 2nd query string. Quote Link to comment https://forums.phpfreaks.com/topic/123283-solved-strip-out-part-of-a-string-should-be-easy-enough/#findComment-636690 Share on other sites More sharing options...
CaptainChainsaw Posted September 8, 2008 Author Share Posted September 8, 2008 I think I've got this sorted. Quote Link to comment https://forums.phpfreaks.com/topic/123283-solved-strip-out-part-of-a-string-should-be-easy-enough/#findComment-636697 Share on other sites More sharing options...
The Little Guy Posted September 8, 2008 Share Posted September 8, 2008 Never Mind.... Forget this post... $str = str_replace("pagenumber","",$url); // doesn't remove the number // OR $str = preg_replace("~pagenumber=(.+?)\&~","",$URL); Quote Link to comment https://forums.phpfreaks.com/topic/123283-solved-strip-out-part-of-a-string-should-be-easy-enough/#findComment-636704 Share on other sites More sharing options...
sasa Posted September 8, 2008 Share Posted September 8, 2008 try <?php $test = 'search.php?pagenumber=2¶m0=a'; $test = parse_url($test); parse_str($test[query], $out); print_r($out); ?> Quote Link to comment https://forums.phpfreaks.com/topic/123283-solved-strip-out-part-of-a-string-should-be-easy-enough/#findComment-636882 Share on other sites More sharing options...
discomatt Posted September 8, 2008 Share Posted September 8, 2008 Alternately <?php $test = 'search.php?pagenumber=2¶m0=a'; list(,$query) = explode( '?', $test ); parse_str( $query, $qVars ); echo $qVars['pagenumber']; ?> Saves you a parse_url call. Quote Link to comment https://forums.phpfreaks.com/topic/123283-solved-strip-out-part-of-a-string-should-be-easy-enough/#findComment-636888 Share on other sites More sharing options...
CaptainChainsaw Posted September 8, 2008 Author Share Posted September 8, 2008 Hey all thanks for all your posts. I had managed to fix it earlier..... I do appreciate your input as always! Cheers again peeps, CC Quote Link to comment https://forums.phpfreaks.com/topic/123283-solved-strip-out-part-of-a-string-should-be-easy-enough/#findComment-636946 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.