Rectangle 27 20

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];
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

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 :) )

Get fragment (value after hash '#') from a URL in php - Stack Overflow

php url anchor