You get url and then apply parse function on url.
eg::
$url = 'http://username:password@hostname/path?arg=value#anchor';
print_r(parse_url($url));
Output::
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)
this fragment is your requirement. If i'm right then try this n got success. :)
Thanks
for get current URL::
function getInstance($uri = 'SERVER')
{
if ($uri == 'SERVER')
{
if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) {
$https = 's://';
} else {
$https = '://';
}
if (!empty ($_SERVER['PHP_SELF']) && !empty ($_SERVER['REQUEST_URI'])) {
$theURI = 'http' . $https . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if (strlen($_SERVER['QUERY_STRING']) && strpos($_SERVER['REQUEST_URI'], $_SERVER['QUERY_STRING']) === false) {
$theURI .= '?'.$_SERVER['QUERY_STRING'];
}
}
else
{
$theURI = 'http' . $https . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'];
if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
$theURI .= '?' . $_SERVER['QUERY_STRING'];
}
}
$theURI = urldecode($theURI);
$theURI = str_replace('"', '"',$theURI);
$theURI = str_replace('<', '<',$theURI);
$theURI = str_replace('>', '>',$theURI);
$theURI = preg_replace('/eval\((.*)\)/', '', $theURI);
$theURI = preg_replace('/[\\\"\\\'][\\s]*javascript:(.*)[\\\"\\\']/', '""', $theURI);
}
echo (string)$theURI;
}