roydukkey Posted July 22, 2009 Share Posted July 22, 2009 Here is the what i need to happen. Much thanks to anyone willing to help. I need to replace 'f=varying-string' from 'f=varying-string&killer=lop&you=pop'. The string need to be replaced no matter where it is. ie. 'killer=lop&f=varying-string&you=pop' I'm trying this: preg_replace( "/^[f=].*(^&.*$)$/is", "", $_SERVER['QUERY_STRING'] ); Quote Link to comment https://forums.phpfreaks.com/topic/166893-help-with-regex-replace/ Share on other sites More sharing options...
ghostdog74 Posted July 22, 2009 Share Posted July 22, 2009 i don't understand what you mean by "no matter where it is", but anyhow, here's something non regex , $str = "f=varying-string&killer=lop&you=pop"; $s = explode("&",$str); $tmp=$s[0]; $s[0]=$s[1]; $s[1]=$tmp; print implode("&",$s); Quote Link to comment https://forums.phpfreaks.com/topic/166893-help-with-regex-replace/#findComment-880169 Share on other sites More sharing options...
jayjay960 Posted July 22, 2009 Share Posted July 22, 2009 Try: /\bf=\b.+/ Quote Link to comment https://forums.phpfreaks.com/topic/166893-help-with-regex-replace/#findComment-880180 Share on other sites More sharing options...
thebadbad Posted July 22, 2009 Share Posted July 22, 2009 There are built in PHP functions for this: <?php parse_str($_SERVER['QUERY_STRING'], $data); unset($data['f']); echo http_build_query($data); ?> Note that http_build_query() requires PHP 5. Quote Link to comment https://forums.phpfreaks.com/topic/166893-help-with-regex-replace/#findComment-880218 Share on other sites More sharing options...
roydukkey Posted July 22, 2009 Author Share Posted July 22, 2009 Thanks all for you posts. thebadbad had the answer i was looking for thanks! Quote Link to comment https://forums.phpfreaks.com/topic/166893-help-with-regex-replace/#findComment-880481 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.