Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Functions...
- // Serialize native Javascript object to JSON. To quote the key names. key=>'key'
- function fix_json( $j ){
- $j = trim( $j );
- $j = ltrim( $j, '(' );
- $j = rtrim( $j, ')' );
- $a = preg_split('#(?<!\\\\)\"#', $j );
- for( $i=0; $i < count( $a ); $i+=2 ){
- $s = $a[$i];
- $s = preg_replace('#([^\s\[\]\{\}\:\,]+):#', '"\1":', $s );
- $a[$i] = $s;
- }
- //var_dump($a);
- $j = implode( '"', $a );
- //var_dump( $j );
- return $j;
- }
- # iCutter Function for PHP 5.x :) - snap particular string from another STRING starting from X and ending at Y.
- $CHKVER = stripos(phpversion(), "5.3");
- if ($CHKVER === false)
- {
- function snap($start,$end,$string)
- {
- // For PHP <= 5.2
- $search = array(stristr($string,$end),$start);
- $snap = str_ireplace($search,"",stristr($string,$start));
- return $snap;
- }
- }
- else
- {
- function snap($start,$end,$string)
- {
- // For PHP >= 5.3
- $portion = str_ireplace($start,'',stristr( stristr($string,$start ,false), $end,true));
- return $portion;
- }
- }
- function isExist($str,$key)
- {
- $pos1 = stripos($str, $key);
- if ($pos1 === false)
- return false;
- else
- return true;
- }
- function getJson($str)
- {
- if(isExist($str,'faredetails'))
- return snap('.faredetails=','};',$str) . '}';
- if(isExist($str,'legdetails'))
- return snap('.legdetails=','}]}',$str) . '}]}';
- if(isExist($str,']='))
- return snap(']=','}',$str) . '}';
- return null;
- }
- // Actual Code Starts from here....
- $data = file_get_contents("http://prismatric.com/keentripo/AirTran.php");
- $data = snap("var isFlexiSearch",';;',$data);
- $data_arr = explode("blrmaa_1",$data);
- // Total Flights..
- $_tot_flight = snap('[',']',$data_arr[count($data_arr)-1]) - 23;
- echo '<pre>';
- $j=0;
- for($i=count($data_arr)-1;$i>=$_tot_flight;--$i)
- {
- $json = fix_json(trim(getJson($data_arr[$i])));
- if($json != null)
- {
- if(isExist($json,'index'))
- {
- $_arr[$j]['index'] = $json;
- $j++;
- }
- if(isExist($json,'leg'))
- $_arr[$j]['leg'] = $json;
- if(isExist($json,'fare'))
- $_arr[$j]['fare'] = $json;
- }
- }
- // $_arr have all flight details in multi-dimentional array + json format
- $jd = json_decode(($_arr[0]["index"])); // 1st flight's 'index'
- echo $jd->{'index'};
- var_dump($jd);
- var_dump($_arr);
- // Pratik Gothaliya & Mayur Pipaliya
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement