<?php
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>REST GEOCODE</title>

    </head>
    <body>

    <center> <img src="http://www.pcmiler.com/img/pcmiler-logo.png" />   </center>
    <br/>
    <h1 align="center"><font color="red" size="12"> REST GEOCODE</font></h1>
    <br/>
  
    <form  name="form1"  method="post"  action="" align="center">

        <label style="font-weight: bolder;padding-right: 10px;"><font color="blue" size="6">API Key</font></label>
        <input  name="apiKey" size="40"  value="<?php if (isset($_POST['apiKey'])) {
    echo htmlentities($_POST['apiKey']);
    } else {
      echo '';
    } 
    ?>">
       
         
    

 
        <span style="padding: 0 10px">&amp;amp;amp;amp;nbsp;</span>
        <input name='submit' type="submit" style=" background: blue ;text-decoration: underline; width: 150px;height: 50px;color: red;font-size: xx-large;font-style: inherit; font-weight: bolder">

    </form>   

<?php
if(isset($_POST['submit'])){

        $apiKey = isset($_POST['apiKey']) ? $_POST['apiKey'] : '';
  $ch = curl_init();
  $data = '?postcode=08540&amp;amp;amp;amp;postcodeFilter=us&amp;amp;amp;amp;region=NA&amp;amp;amp;amp;dataset=Current';
   $target_url = 'http://pcmiler.alk.com/apis/rest/v1.0/Service.svc/locations' . $data;
        //This needs to be the full path to the file you want to send.
  

  $headers = array(
    'Content-type: application/json',
    'Authorization:' . $apiKey . "'",
    'Host: pcmiler.alk.com'
  );


  

        $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$target_url);

  
  

  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  
  $curl_response = curl_exec($ch);
  if ($curl_response === false) {
    $info = curl_getinfo($ch);
    curl_close($ch);
    die('error occured during curl exec. Additioanl info: ' . var_export($info));
  }
  curl_close($ch);



  
  if (isset($decoded->response->status) &amp;amp;amp;amp;&amp;amp;amp;amp; $decoded->response->status == 'ERROR') {
    die('error occured: ' . $decoded->response->errormessage);
  }
  
  //  header('Content-Type: application/json')

  
  //$json = json_decode($curl_response);
  
  //echo json_encode($json, JSON_PRETTY_PRINT) ;
 


     prettyPrint($curl_response);

}


?>
<?php
function prettyPrint( $json ){

$result = '';
$level = 0;
$in_quotes = false;
$in_escape = false;
$ends_line_level = NULL;
$json_length = strlen( $json );

for( $i = 0; $i < $json_length; $i++ ) {
    $char = $json[$i];
    $new_line_level = NULL;
    $post = "";
    if( $ends_line_level !== NULL ) {
        $new_line_level = $ends_line_level;
        $ends_line_level = NULL;
    }
    if ( $in_escape ) {
        $in_escape = false;
    } else if( $char === '"' ) {
        $in_quotes = !$in_quotes;
    } else if( ! $in_quotes ) {
        switch( $char ) {
            case '}': case ']':
                $level--;
                $ends_line_level = NULL;
                $new_line_level = $level;
                $char.="<br>";
                for($index=0;$index<$level-1;$index++){$char .= str_repeat('&amp;amp;amp;amp;nbsp;', 5);}
                break;

            case '{': case '[':
                $level++;
                $char.="<br>";
                for($index=0;$index<$level;$index++){$char .= str_repeat('&amp;amp;amp;amp;nbsp;', 5);}
                break;
            case ',':
                $ends_line_level = $level;
                $char.="<br>";
                for($index=0;$index<$level;$index++){$char .= str_repeat('&amp;amp;amp;amp;nbsp;', 5);}
                break;

            case ':':
                $post = " ";
                break;

            case "\t": case "\n": case "\r":
                $char = "";
                $ends_line_level = $new_line_level;
                $new_line_level = NULL;
                break;
        }
    } else if ( $char === '\\' ) {
        $in_escape = true;
    }
    if( $new_line_level !== NULL ) {
        $result .= "\n".str_repeat( "\t", $new_line_level );
    }
    $result .= $char.$post;
}


echo "RESULTS ARE: <br><br>$result";
return $result;
}
?>
</body>
</html>


This sample may use features that are only available in our Premium WebServices. Please refer to our Features page to confirm what feature level you currently subscribe to.