Advertisement
eboye

WP - Android Market QR Code

Mar 11th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. else if (strpos($url, "play.google.com/store") !== false) {
  2.  
  3.         // what to find in the string, in order to extract what we want
  4.         $findthis = "?id=";
  5.         // check where in the link "?id=" appears. we need the name of the app package.
  6.         // to find the position of the start of the last occurence of a string, the idea is to reverse both $needle and $haystack, use strpos to
  7.         // find the first occurence of $needle in $haystack, then count backwards by the length of $needle. finally, subtract $pos from length of $haystack.
  8.         $packagepos = strlen($url) - (strpos(strrev($url), strrev($findthis)) + strlen($findthis));
  9.         $packagename = substr($url,$packagepos+4); // extract the part of the link after "?id=" to the end of the string, that's the package name
  10.         // check where/if the ampersand is that the web Market sometimes adds, so we can clean up the URL
  11.         $ampersandpos = strpos($packagename, "&");
  12.         // if the ampersand's position isn't bigger than 0, it doesn't exist, so ignore it
  13.         if ($ampersandpos >0) {
  14.             // extract the package name
  15.             $packagename = substr($packagename, 0, $ampersandpos);
  16.             // create a new Web Market URL, without the redundant info after the ampersand
  17.             $url = substr($url, 0, strpos($url, "&"));
  18.         }
  19.         // create the Android Market search string for the QR code
  20.         $qrURL = "market://search?q=pname:".$packagename;
  21.  
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement