我想从保存URL的变量中获取参数
我得到了以下变量:$lastPage
,它保存上一页的URI。
我想从中获取一个参数。
我用javascript(用于其他用途)获得了以下脚本
function getUrlVar(key)
{
var result = new RegExp(key + '=([^&]*)', 'i').exec(window.location.search);
return result && unescape(result[1]) || '';
}
我想要这样的东西,但对于PHP。
非常感谢
$url = 'http://php.net/manual/en/function.parse-url.php?id=my_awesome_id';
$arr = parse_url($url);
parse_str($arr['query']);
echo $id; // my_awesome_id
参考:
parse_str
parse_url
您可以在php中使用preg_match()
或preg_match_all()
,这将为您提供正则表达式功能。
http://php.net/manual/en/function.preg-match.php