从#id = 3333中获取参数值

时间:2011-01-17 09:03:36

标签: php javascript

我有这个,

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'
    }
}

如果不支持window.history,则为#id = 3333。现在,如果您加载页面并且它有一个location.hash,它的$ .post请求它与file.php:

$.post('do_something.php', { hash: hash }, function(result) { $('#photos').html(result); });

在do_something中我用$ _POST ['hash']抓取它。现在$ _POST ['hash']将包含#id = 3333。我如何划分参数并抓住价值'3333'?

1 个答案:

答案 0 :(得分:1)

有很多方法可以将字符串#id=3333转换为字符串3333

拆分'=':

$parts = explode('#', $inputString);
$value = $parts[1];

删除前四个字符:

$value = substr($inputString, 3);
相关问题