// MIT License // This script pulls operating system market share data from Net Applications, // groups it according to the groups defined in $grouping, // and writes the results to a file named market-shares.txt. $months = array( 'January' => '01', 'February' => '02', 'March' => '03', 'April' => '04', 'May' => '05', 'June' => '06', 'July' => '07', 'August' => '08', 'September' => '09', 'October' => '10', 'November' => '11', 'December' => '12'); $grouping = array( 'Windows' => array('Win64', 'Windows 2000', 'Windows 7', 'Windows 95', 'Windows 98', 'Windows ME', 'Windows NT', 'Windows Vista', 'Windows XP 64-bit Edition', 'Windows XP'), 'Mac' => array('Mac OS X (no version reported)', 'Mac OS X 10.4', 'Mac OS X 10.5', 'Mac OS X 10.6', 'Mac OS X Mach-O', 'Mac OS', 'MacIntel', 'MacOS'), 'Linux' => array('Linux'), 'Other device' => array('FreeBSD', 'Nintendo Wii', 'PLAYSTATION 3', 'Pike', 'SunOS', 'Unknown', 'X11'), 'iPhone/iPod' => array('iPhone', 'iPod'), 'Java' => array('Java ME'), 'Symbian' => array('Series60', 'Symbian'), 'Windows Mobile' => array('Windows CE', 'Windows Mobile'), 'Android' => array('Android 1.0', 'Android 1.1', 'Android 1.5', 'Android 1.6', 'Android 2.0'), 'BlackBerry' => array('BlackBerry'), 'Palm' => array('PalmOS', 'webOS'), 'Other handheld' => array('Hiptop', 'KDDI', 'PSP', 'FOMA')); $os_groups = array_keys($grouping); $os_list = array(); foreach($os_groups as $os) foreach($grouping[$os] as $entry) $os_list[$entry] = $os; echo 'Downloading and grouping market share data...'; $last = ''; for ($i=108; $i<144; $i++) { // from January 2008 to December 2010 $string = file_get_contents('http://marketshare.hitslink.com' . '/report.aspx?qprid=10&qptimeframe=M&qpsp=' . $i . '&qpmr=30&qpdt=1&qpct=3&qpf=13'); if ($string == $last) break; $last = $string; $string = substr($string, strpos($string, 'loadXML($string); $date = explode(', ', $xml->getElementsByTagName('timeframe')->item(0)->nodeValue); $month = $date[1] . '-' . $months[$date[0]]; $rows = $xml->getElementsByTagName('row'); if ($rows->length == 0) break; for ($j=0; $j<$rows->length; $j++) { $os = $rows->item($j)->getElementsByTagName( 'value1')->item(0)->nodeValue; $share = trim($rows->item($j)->getElementsByTagName( 'value2')->item(0)->nodeValue, '%'); if ($share == 0) continue; if (!isset($os_list[$os])) exit("Unknown operating system: $os\n"); if (isset($ms[$month][$os_list[$os]])) $ms[$month][$os_list[$os]] += $share; else $ms[$month][$os_list[$os]] = $share; } } $fp = fopen('market-shares.txt', 'w'); fwrite($fp, "Month\t" . implode("\t", $os_groups) . "\n"); foreach ($ms as $month => $values) { fwrite($fp, $month); foreach ($os_groups as $os) if (isset($values[$os])) fwrite($fp, "\t" . sprintf("%.2f", $values[$os])); else fwrite($fp, "\t0.00"); fwrite($fp, "\n"); } fclose($fp); echo "\nDone.\n"; ?>