'01', 'February' => '02', 'March' => '03', 'April' => '04', 'May' => '05', 'June' => '06', 'July' => '07', 'August' => '08', 'September' => '09', 'October' => '10', 'November' => '11', 'December' => '12'); $os_groups = array('Windows', 'Mac', 'Linux', 'Other device', 'iPhone/iPod', 'Windows CE', 'Symbian', 'Android', 'BlackBerry', 'Other handheld'); $os_list = array( 'Windows' => 'Windows', 'Windows Vista' => 'Windows', 'Windows XP' => 'Windows', 'Windows XP 64-bit Edition' => 'Windows', 'Windows 2000' => 'Windows', 'Windows ME' => 'Windows', 'Windows 98' => 'Windows', 'Windows 95' => 'Windows', 'Windows NT' => 'Windows', 'Windows 7' => 'Windows', 'Win64' => 'Windows', 'MacIntel' => 'Mac', 'Mac OS' => 'Mac', 'Mac OS X 10.4' => 'Mac', 'Mac OS X 10.5' => 'Mac', 'Mac OS X Mach-O' => 'Mac', 'Mac OS X (no version reported)' => 'Mac', 'MacPPC=/conditioning_book.html' => 'Mac', 'Linux' => 'Linux', 'Web TV' => 'Other device', 'SunOS sun4u' => 'Other device', 'FreeBSD' => 'Other device', 'FreeBSD i386' => 'Other device', 'OS/2' => 'Other device', 'SunOS' => 'Other device', 'SunOS5.5.1' => 'Other device', 'FreeBSD i386 X11' => 'Other device', 'Nintendo Wii' => 'Other device', 'PLAYSTATION 3' => 'Other device', 'Pike' => 'Other device', 'Pike v7.6 release 92' => 'Other device', 'Java ME' => 'Other device', 'Unknown' => 'Other device', 'iPhone' => 'iPhone/iPod', 'iPod' => 'iPhone/iPod', 'Windows CE' => 'Windows CE', 'Symbian' => 'Symbian', 'Symbian OS' => 'Symbian', 'Series60' => 'Symbian', 'Android 1.0' => 'Android', 'Android 1.1' => 'Android', 'Android 1.5' => 'Android', 'PSP' => 'Other handheld', 'Hiptop' => 'Other handheld', 'PalmOS' => 'Other handheld', 'BlackBerry' => 'BlackBerry'); echo 'Downloading and grouping market share data...'; for ($i=72; $i<144; $i++) { // from January 2005 to December 2010 $xml = new DOMDocument(); $xml->load("http://marketshare.hitslink.com/report.aspx?qprid=10&qptimeframe=M&qpsp=$i&qpmr=30&qpdt=1&qpct=3&qpf=13"); $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"; ?>