Parsing and encoding directions

This is continued from the previous post. We now wanted to parse the array of directions to extract the steps. Another big challenge was to fit the large amount of data into the QR code. We used the PHP GD library to maps the occurrence of the words in a bar chart and encode them .The following code does exactly this.

<pre>//:::::::::::::::: Retrieves the useful stuff from the json file ::::::::::::::::
$jsonIterator = new RecursiveIteratorIterator(    new RecursiveArrayIterator(json_decode($data, TRUE)), decide the     RecursiveIteratorIterator::SELF_FIRST);
foreach ($jsonIterator as $key => $val)
if(!is_array($val)) {
if($key == "html_instructions")
$directions[$counter] = array("step" => $val);
$output .= $val;
$output .= ".";
//::::::::::: Reduce the content with 1 to 1 linkage ::::::::::::::::
//echo $output."<br/><br/>";
//$response = $_GET["callback"] . "(" . json_encode($directions) . ")";

Lets briefly understand what are we doing.
We are using The RecursiveIterator interface of php to iterate over the array and extracts the steps. We assume a key:value pair and check if the key is html_instructions then append it to the $output string.
After that we are simply replacing the words in the array $common with the equivalent symbols in array $encode


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s