PHP preg_match,从Android URL地址中查找包名

I need to get Android package name from the URL address.

Here is what I have done.

$url = 'https://play.google.com/store/apps/details?id=com.gamevil.projectn.global&feature=featured-apps#?t=W251bGwsMSwyLDIwMywiY29tLmdhbWV2aWwucHJvamVjdG4uZ2xvYmFsIl0.';
        preg_match("~id=(\d+)~", $url, $matches);
        $package_name = $matches[1];

        echo $package_name;

Package name should be "com.gamevil.projectn.global"

However, my code is not working.

Is there something that I miss?

you can do this by parse_url function

<?php
$url = 'https://play.google.com/store/apps/details?id=com.gamevil.projectn.global&feature=featured-apps#?t=W251bGwsMSwyLDIwMywiY29tLmdhbWV2aWwucHJvamVjdG4uZ2xvYmFsIl0.';
$arr =parse_url($url);
$new = explode("&",$arr['query']);
$new1 = explode("=",$new[0]);
echo($new1[1] );

output

com.gamevil.projectn.global

jsFiddle

Maybe this can help you:

$url = 'https://play.google.com/store/apps/details?id=com.gamevil.projectn.global&feature=featured-apps#?t=W251bGwsMSwyLDIwMywiY29tLmdhbWV2aWwucHJvamVjdG4uZ2xvYmFsIl0.';
    preg_match("/id=(.*?)&/", $url, $matches);
    $package_name = $matches[1];

    echo $package_name;

preg_match will no find everything between id= and &.

But a better solution is to use parse_url to parse the url and this function will return the components of the url.