Reputation: 550
I have a url like this:
http://ar.com.expedia.www/Mendoza-Hoteles-Mod-Hotels-Mendoza.h3385807.Informacion-Hotel?chkin=01/05/2014&chkout=04/05/2014&rm1=a2&
Please notice the & at the end of the url.I need to get this url from a restful web service. How can I grab the whole url as a parameter including the trailing ampersand. Ignore the reversed domain. It is taken care of.
I have tried this:
$url = array_shift($_GET);
foreach ($_GET as $key => $value) {
$url .= '&' . $key . (($value == '') ? '' : '=') . $value;
}
Upvotes: 1
Views: 103
Reputation: 13
Here You Go!!!
<?php
$url = 'http://www.IrfanAnsari.com/embedviz?q=select+col9+from+1c16ZytvOGsazT5r4borWzDSKmRy1dyeCqzOHdnWb&viz=MAP&h=false&lat=28.098107336734692&lng=68.93999515039059&t=1&z=6&l=col9&y=2&tmplt=2&hml=GEOCODABLE';
function grab_url($url) {
if(!empty($url)) {
$urllist=parse_url($url);
if(is_array($urllist) && isset($urllist["query"])) {
$keyvalue_list=explode("&",($urllist["query"]));
$keyvalue_result=array();
foreach($keyvalue_list as $key=>$value) {
$keyvalue=explode("=",$value);
if(count($keyvalue)==2)
$keyvalue_result[$keyvalue[0]]=$keyvalue[1];
}
}
}
return $keyvalue_result;
}
var_dump( grab_url($url) );
?>
Upvotes: 0
Reputation: 471
an example using regex
check if its that what you want
<?php
$a="http://ar.com.expedia.www/Mendoza-Hoteles-Mod-Hotels-Mendoza.h3385807.Informacion- Hotel?chkin=01/05/2014&chkout=04/05/2014&rm1=a2&";
preg_match("/(?:http(?:s)?:\/\/)(.+)$/","$a",$result);
echo $result[1];
?>
Upvotes: 0
Reputation: 392
Start by parse_url
:
var_dump(
parse_url("http://ar.com.expedia.www/Mendoza-Hoteles-Mod-Hotels-Mendoza.h3385807.Informacion-Hotel?chkin=01/05/2014&chkout=04/05/2014&rm1=a2&")
);
Result would be as
array(4) {
["scheme"]=>
string(4) "http"
["host"]=>
string(18) "ar.com.expedia.www"
["path"]=>
string(62) "/Mendoza-Hoteles-Mod-Hotels-Mendoza.h3385807.Informacion-Hotel"
["query"]=>
string(42) "chkin=01/05/2014&chkout=04/05/2014&rm1=a2&"
}
You can then use explode
for the ["query"]
to move on.
Upvotes: 1