[英]Grabbing param value from #id=3333
I have this, 我有这个,
var stateObj = { foo: "foo" };
function change_my_url()
{
if (window.history && window.history.pushState){
history.pushState(stateObj, "page 2", "foo.html?id=3333");
}else{
location.hash = '#id=3333'
}
}
In case window.history isnt supported, it will be #id=3333. 如果不支持window.history,它将为#id = 3333。 Now if you load the page and it has a location.hash, it $.post request to file.php with it:
现在,如果您加载该页面,并且该页面具有location.hash,则它向file.php发出$ .post请求:
$.post('do_something.php', { hash: hash }, function(result) { $('#photos').html(result); });
in do_something im grabbing it with $_POST['hash'];. 在do_something中,我用$ _POST ['hash'];抓取了它。 Now $_POST['hash'] will contain #id=3333.
现在$ _POST ['hash']将包含#id = 3333。 How can i divide in params and grab the value, '3333' ?
我如何划分参数并获取值“ 3333”?
There are many ways to turn the string #id=3333
into the string 3333
. 有很多方法可以将字符串
#id=3333
转换为字符串3333
。
Split on '=': 在'='上分割:
$parts = explode('#', $inputString);
$value = $parts[1];
Remove the first four chars: 删除前四个字符:
$value = substr($inputString, 3);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.