Php 如何从字符串中获取id参数?

Php 如何从字符串中获取id参数?,php,regex,preg-match,Php,Regex,Preg Match,我有字符串:apps/details?id=it.repix.android 如何获取id参数的值 我试过正则表达式: $pattern = '/id=(.*)$/'; preg_match($pattern, $url, $matches, PREG_OFFSET_CAPTURE); $id = $matches[1][0]; 但是它有时不正确您可以使用全局变量$\u GET; $id=$_GET['id'] 就是这样我从字符串中获取id,而不是从URL$

我有字符串:
apps/details?id=it.repix.android

如何获取
id
参数的值

我试过正则表达式:

 $pattern = '/id=(.*)$/';
        preg_match($pattern, $url, $matches, PREG_OFFSET_CAPTURE);

        $id = $matches[1][0];

但是它有时不正确

您可以使用全局变量$\u GET; $id=$_GET['id']


就是这样

我从字符串中获取
id
,而不是从URL$str='apps/details?id=it.repix.android&test=1'$str=爆炸('?',$str)[1];parse_str($str,$get);var_dump($get['id'])
$s=“apps/details?id=it.repix.android”$qry=parse_url($s,PHP_url_QUERY);parse_str($qry,$res);echo$res[“id”],请参阅