Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/175091-solved-url-breakdown/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/175091-solved-url-breakdown/#findComment-922825
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/175091-solved-url-breakdown/#findComment-922832
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/175091-solved-url-breakdown/#findComment-922837
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/175091-solved-url-breakdown/#findComment-922840
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.