monkeytooth Posted September 22, 2009 Share Posted September 22, 2009 Ok with the use of: $url = 'http://jobsearch.monster.com/getjob.asp?JobID=83493606&AVSDM=2009-09-22%2003:03:00&WT.mc_n=RSS2005_JSR'; print_r(parse_url($url)); I get an output of: Array ( [scheme] => http [host] => jobsearch.monster.com [path] => /getjob.asp [query] => JobID=83493606&AVSDM=2009-09-22%2003:03:00&WT.mc_n=RSS2005_JSR ) What I want to do is catch one specific var in that url the JobID=83493606 more specific the 83493606 or what ever the = would be in any given scenario. But im not sure which function would be the best route to take. I am open to ideas? anyone got any? Quote Link to comment https://forums.phpfreaks.com/topic/175091-solved-url-breakdown/ Share on other sites More sharing options...
AviNahum Posted September 22, 2009 Share Posted September 22, 2009 simply, $_GET['JobID']; echo $_GET['JobID']; Quote Link to comment https://forums.phpfreaks.com/topic/175091-solved-url-breakdown/#findComment-922821 Share on other sites More sharing options...
monkeytooth Posted September 22, 2009 Author Share Posted September 22, 2009 Ahh, I should have specified that the url's in question are not being passed through the browsers as a link or form post or anything like that. The url is being pulled from another source, used as a var/string in it of itself and what I need to do is break down that string a bit more, in this case to catch the specific "JobID" and only the JobID. But in essence the desired output that I am looking for is the same as if I would use $_GET/$_POST ['JobID'] on my own internal scripts. Quote Link to comment https://forums.phpfreaks.com/topic/175091-solved-url-breakdown/#findComment-922825 Share on other sites More sharing options...
Mark Baker Posted September 22, 2009 Share Posted September 22, 2009 have a look at parse_str() Quote Link to comment https://forums.phpfreaks.com/topic/175091-solved-url-breakdown/#findComment-922830 Share on other sites More sharing options...
Bricktop Posted September 22, 2009 Share Posted September 22, 2009 Hi monkeytooth, How about using a function such as: function find_jobid($start,$end,$total){ $total = stristr($total,$start); $f2 = stristr($total,$end); return substr($total,strlen($start),-strlen($f2)); } $job_id = find_jobid("JobID=","&",$url); echo $job_id; As long as the url stays the same this should work, it just outputs the data between JobID= and the & after the Job ID number from the URL. Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/175091-solved-url-breakdown/#findComment-922832 Share on other sites More sharing options...
monkeytooth Posted September 22, 2009 Author Share Posted September 22, 2009 I'm pretty sure the string will stay for the most part the same, but lets say on the off chance it does not and JobID= moves else where in the string, is that going to effect this function? Quote Link to comment https://forums.phpfreaks.com/topic/175091-solved-url-breakdown/#findComment-922836 Share on other sites More sharing options...
RichardRotterdam Posted September 22, 2009 Share Posted September 22, 2009 There are many ways to solve this one here is one that gets all the params in the url <?php $url = 'http://jobsearch.monster.com/getjob.asp?JobID=83493606&AVSDM=2009-09-22%2003:03:00&WT.mc_n=RSS2005_JSR'; $params = getUrlValues($url); echo "Value of JobID = ",$params['JobID']; function getUrlValues($url){ $values = parse_url($url); $urlPieces = explode("&" , $values['query']); $urlVals = array(); foreach($urlPieces as $urlPiece){ $tmp = explode("=" , $urlPiece); $urlVals[$tmp[0]] = $tmp[1]; } return $urlVals; } You could prob also use a regular expression Quote Link to comment https://forums.phpfreaks.com/topic/175091-solved-url-breakdown/#findComment-922837 Share on other sites More sharing options...
trq Posted September 22, 2009 Share Posted September 22, 2009 There are many ways to solve this one here is one that gets all the params in the url <?php $url = 'http://jobsearch.monster.com/getjob.asp?JobID=83493606&AVSDM=2009-09-22%2003:03:00&WT.mc_n=RSS2005_JSR'; $params = getUrlValues($url); echo "Value of JobID = ",$params['JobID']; function getUrlValues($url){ $values = parse_url($url); $urlPieces = explode("&" , $values['query']); $urlVals = array(); foreach($urlPieces as $urlPiece){ $tmp = explode("=" , $urlPiece); $urlVals[$tmp[0]] = $tmp[1]; } return $urlVals; } You could prob also use a regular expression Or (as has been pointed out) you could simply use the built in parse_str function which is made for doing precisely this. Quote Link to comment https://forums.phpfreaks.com/topic/175091-solved-url-breakdown/#findComment-922840 Share on other sites More sharing options...
RichardRotterdam Posted September 22, 2009 Share Posted September 22, 2009 Overlooked the str_parse post while posting Quote Link to comment https://forums.phpfreaks.com/topic/175091-solved-url-breakdown/#findComment-922857 Share on other sites More sharing options...
Bricktop Posted September 22, 2009 Share Posted September 22, 2009 Hi monkeytooth, I overlooked parse_str too. Using parse_str() do the following: $url = 'http://jobsearch.monster.com/getjob.asp?JobID=83493606&AVSDM=2009-09-22%2003:03:00&WT.mc_n=RSS2005_JSR'; parse_str($url); echo $JobID; Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/175091-solved-url-breakdown/#findComment-922859 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.