A) already have url with #hash in PHP? Easy! Just parse it out !
if( strpos( $url, "#" ) === false ) echo "NO HASH !";
else echo "HASH IS: #".explode( "#", $url )[1]; // arrays are indexed from 0
Or in "old" PHP you must pre-store the exploded to access the array:
$exploded_url = explode( "#", $url ); $exploded_url[1];
B) You want to get a #hash by sending a form to PHP?
=> Use some JavaScript MAGIC! (To pre-process the form)
var forms = document.getElementsByTagName('form'); //get all forms on the site
for(var i=0; i<forms.length;i++) forms[i].addEventListener('submit', //to each form...
function(){ //add a submit pre-processing function that will:
var hidden = document.createElement("input"); //create an extra input element
hidden.setAttribute('type','hidden'); //set it to hidden so it doesn't break view
hidden.setAttribute('name','fragment'); //set a name to get by it in PHP
hidden.setAttribute('value',window.location.hash); //set a value of #HASH
this.appendChild(hidden); //append it to the current form
});
Depending on your form
's method
attribute you get this hash in PHP by:
$_GET['fragment']
or $_POST['fragment']
Possible returns: 1. ""
[empty string] (no hash) 2. whole hash INCLUDING the #
[hash] sign (because we've used the window.location.hash
in JavaScript which just works that way :) )
C) You want to get the #hash in PHP JUST from requested URL?
YOU CAN'T !
...(not while considering regular HTTP requests)...
...Hope this helped :)