Canman2005 Posted February 22, 2007 Share Posted February 22, 2007 Hi all I have a value defined like $url = $_SERVER['HTTP_REFERER']; print $url; Which produces a url with a did number which can be something like 55 and a tid number which can be something like 3 a full example is http://www.myweb.com/files/page.php?did=55&tid=3 I want to get php to format whatever is outputted and then remove everything before the did number and everything after it. With the above, it would remove the first part http://www.myweb.com/files/page.php?did= and then the second part &tid=3 and leave me with just 55 Can this be done? Its hard to explain what I mean but someone may understand me Thanks in advance Dave Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 23, 2007 Share Posted February 23, 2007 Try this: <?php $pattern = '/[^t=][0-9]+/'; preg_match($pattern, $url, $matches); echo $matches[0]; //55 ?> If you have numbers in the file name or website or you have more variables in the url, you will need to add to $pattern variable. I'm sure someone could make a more bullet proof expression, but for your example, it should work. Quote Link to comment Share on other sites More sharing options...
PseudoZen Posted February 23, 2007 Share Posted February 23, 2007 Assuming that we're talking about grabbing the URL parameters from the currently loaded page, here's a simple method that avoids regular expressions altogether: $args=$_GET; echo $args['did']; Quote Link to comment Share on other sites More sharing options...
Canman2005 Posted February 23, 2007 Author Share Posted February 23, 2007 Thanks Guys Quote Link to comment 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.