Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
188 lines (161 sloc) 5.99 KB
<!doctype html>
<html lang="en">
<meta charset="utf-8">
// Basic API to simplexml function
function My_simplexml_load_file($URL)
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$xml = simplexml_load_string(curl_exec($ch));
return $xml;
* Splits up a string into an array similar to the explode() function but according to CamelCase.
* Uppercase characters are treated as the separator but returned as part of the respective array elements.
* @author Charl van Niekerk <>
* @param string $string The original string
* @param bool $lower Should the uppercase characters be converted to lowercase in the resulting array?
* @return array The given string split up into an array according to the case of the individual characters.
function explodeCase($string, $lower = true)
// Split up the string into an array according to the uppercase characters
$array = preg_split('/([A-Z][^A-Z]*)/', $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
// Convert all the array elements to lowercase if desired
if ($lower) {
$array = array_map(strtolower, $array);
// Return the resulting array
return $array;
* bytes() function
* number format and add the appropriate abbreviation for test results
function bytes($a) {
$unim = array("B","KB","MB","GB","TB","PB");
$c = 0;
while ($a>=1024) {
$a = $a/1024;
return number_format($a,($c ? 2 : 0),",",".")." ".$unim[$c];
// set some default values
$cityInfo = null;
$safeLocation ="";
if(isset($_GET['city'])) {
$encodedCity = urlencode($_GET['city']);
$apiURL = "*%20from%20query.multi%20where%20queries%3D'%0A%09select%20*%20from%20fcc.bbtest%20where%20(latitude%2C%20longitude)%20in%20(select%20centroid.latitude%2C%20centroid.longitude%20from%20geo.places%20where%20text%3D%22" . $encodedCity . "%22)%3B%0A%09select%20*%20from%20geo.places(1)%20where%20text%3D%22" . $encodedCity . "%22%0A%09'&";
$cityInfo = My_simplexml_load_file($apiURL);
$safeLocation = htmlspecialchars($_GET['city']);
foreach($cityInfo->results->results as $results){
if(isset($results->SpeedTestCounty)) {
$tests = (array) $results->SpeedTestCounty;
elseif(isset($results->place)){ // we'll use this in the aside.
$placeInfo = (array) $results->place;
} // end foreach results
} // end if
if(!empty($safeLocation)) {
$title = "FCC Licenses for $safeLocation" ;
$title = 'Find the FCC licenses for a city';
print $title;
<meta name="description" content="This page will display FCC information about a city">
<!--the following javascript needs to go in the head. it lets i.e. recognize the new html5 tags -->
<!--[if lt IE 9]>
<script src=""></script>
<!-- CSS from Yahoo's YUI3 library. These set the baseline styles, fonts, and grids. -->
<link rel="stylesheet" type="text/css" href="">
<!-- location hack specific styles -->
<link rel="stylesheet" type="text/css" href="location.css">
<body class="yui3-g">
<header role="banner" class="yui3-u-1">
<h1>License information for <?php print $safeLocation; ?></h1>
<div id="cityChooser">
<div id="status">Checking location</div>
<form action="/examples/location/" role="search">
<label for="city">Search for a city</label>
<input type="search" name="city" id="city" required placeholder="New York" >
<section role="main" class="yui3-u-2-3">
<header><h1>Licensing and other data about <?php print $safeLocation; ?></h1></header>
<section class="tests">
<header><h1>Broadband tests</h1></header>
foreach ($tests as $test =>$value){
//explodeCase changes camel case to an array, implode puts it back into a sentence. and then uppercase first letter
$testFormatted = ucwords( implode(' ', explodeCase( $test, false ) ) );
$valueFormatted = bytes($value);// show kb or mb if appropriate
print "<dt>$testFormatted</dt><dd>$valueFormatted</dd>";
<p>This section is powered by the FCC's Broadband Test API</p>
<aside role="complementary" class="yui3-u-1-3">
<table summary="this table summarizes the geographic details for <?print $safeLocation; ?>">
<th scope="col">Detail</th>
<th scope="col">Value</th>
<td><?php print $placeInfo['name'] . ', '. $placeInfo['admin1'] ;?></td>
<td><?php print $placeInfo['woeid']; ?></td>
<td>Area Rank</td>
<td><?php print $placeInfo['areaRank']; ?></td>
<td>Population Rank (for the United States)</td>
<td><?php print $placeInfo['popRank']; ?></td>
}// end if get:city
<footer role="content-info" class="yui3-u-1">copyright 2010</footer>
<script src="location.js"></script>