Created
April 21, 2016 03:09
-
-
Save dimmduh/464b755bb6a12b516dd8468e2185ed5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static function getPackageNameFromUrl($url, $check_on_google_play = true) | |
{ | |
$url = trim(urldecode($url)); | |
$parsedUrl = parse_url($url); | |
//add scheme if null | |
if (empty($parsedUrl['scheme']) && !empty($parsedUrl['query'])){ | |
$url = 'https://' . $url; | |
$parsedUrl = parse_url($url); | |
} | |
if (empty($parsedUrl['query'])) { | |
if (self::validatePackageName($url, $check_on_google_play)) { | |
return $url; | |
} | |
} else { | |
if ($parsedUrl['path'] == '/store/apps/details' && !empty($parsedUrl['query'])) { | |
$attr = Utils::convertUrlQuery($parsedUrl['query']); | |
if (!empty($attr['id']) && self::validatePackageName($attr['id'], $check_on_google_play)) { | |
return $attr['id']; | |
} | |
} else if ($parsedUrl['path'] == '/apps/publish/' && !empty($parsedUrl['fragment'])) { | |
$parts = explode("p=", $parsedUrl['fragment']); | |
if (count($parts) == 2 && self::validatePackageName($parts[1], $check_on_google_play)) { | |
return $parts[1]; | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment