Reputation: 25
This is my url
http://localhost:8888/App.php#?ID=1S
I needed the 1S
as a variable for using it with a query.
Upvotes: 1
Views: 5102
Reputation: 42093
If you want to parse URL as string:
$str = 'http://localhost:8888/App.php#?ID=1S';
$temp = explode( "?", $str );
$result = explode( "=", $temp['1'] );
echo $result['1'];
If you want to get it on server side:
Hash value is not sent to server side. So it impossible to get it on server side but you can use javascript to do some trick.
Using JavaScript/jQuery: (tags are not added though)
<script>
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('#') + 1).split('&');
hash = hashes[0].split('=');
alert( hash['1'] );
// you can use jQuery.ajax() here to send this value to server side.
</script>
Upvotes: 1
Reputation: 3072
I guess that the only way to do this is by an AJAX request, here is a simplified example:
the index page
<!doctype html>
<html>
<head>
<title>Website</title>
<script type="text/javascript">
var url = document.location;
url = url.toString();
var getVal = url.split("#");
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('GET', 'App.php'+getVal[1], true);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
alert(xmlhttp.responseText);
}
}
xmlhttp.send();
</script>
</head>
<body>
</body>
</html>
the App.php page
<?php
if (isset($_GET['url'])) echo 'url : ' . $_GET['url'];
?>
Upvotes: 0
Reputation:
$url = "http://localhost:8888/App.php#?ID=1S&another=3";
$a = parse_url($url);
parse_str($a["fragment"],$arr);
print_r($arr);
outputs:
Array (
[?ID] => 1S
[another] => 3
);
if you can live accessing the first parameter with "?ID"
Upvotes: 0
Reputation: 3034
echo parse_url('http://localhost:8888/App.php#?ID=1S', PHP_URL_FRAGMENT);
OR
echo parse_url($_SERVER['QUERY_STRING'], PHP_URL_FRAGMENT);
If you need to parse it further:
$x = parse_url($_SERVER['QUERY_STRING'], PHP_URL_FRAGMENT);
parse_str($x, $arr);
echo $arr['ID']
Upvotes: 0