无法对使用php中的curl检索的数据执行任何操作

时间:2015-09-24 05:28:23

标签: php json curl

我正在尝试从特定网站获取数据。最初我试图使用普通$.ajax()方法检索数据,但由于跨域问题,我放弃了这个想法。现在我正在尝试使用PHP的curl函数获取相同的数据。我在这方面取得了成功,但我期待json响应,但我在json数据的末尾得到某种json +其他字符串。我甚至试图用PHP的字符串操作删除该填充,但我无法对该数据执行任何类型的操作。那么,有没有办法做到这一点?即使我试图将$string变量存储在任何文本文件的日志中,它也会保存html代码而不是下面发布的respose。 这是我的代码:

<?php
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, "http://www.example.com/do/mapsearch/getResults_ajax");
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POSTFIELDS, 'city=12&map_type=listing&latlongsearch=1&encrypted_input=UiB8IFFTIHwgUyB8IzIjICB8IG11bWJhaSB8IzMjICB8IE5SSSB8IFkgIzIxI3wgIHwgMSw0LDIsMyw5MCw1LDIyIHwgMTIgfCMxIyAgfCBPLEEsQiMzIyB8IDEsNCwyLDMsOTAsNSwyMiM1IyB8IE8sQSxCICMzMSN8ICA%3D&keyword=&sortby=&mapsearch=1&locality_array=null&building_id=&latitude=19.137212294689522&longitude=72.8479625817871&latlongsearchdistance=3&page=1');
        curl_setopt($ch, CURLOPT_POST, 1);   

        $string = curl_exec($ch);

                // it's not even printing these two lines
        echo "<br /><br/><br/>";
        echo "hie";

        echo curl_error($ch);

        curl_close($ch);

                // tring to get type of response but not printing anything on web page
        echo gettype($string);


    ?>

以下是我的回复部分:

{"total":2987,"resultsCount":30,"results":[{"PROP_ID":"K19962871","SPID":19962871,"VERIFIED":"N","PROFILEID":"509882","SHORTLISTED":"N","TYPE_DISP":"Apartment","AREA_UNIT":"Sq.Ft.","AREA":580,"AREA_TYPE":"Super built-up ","LOCALITY_ID":4962,"BUILDING_ID":0,"IS_XID_ATTACHED":0,"PRICE_DISP":"86 Lac","CITY":"Mumbai Andheri-Dahisar","LOCALITY":"Jogeshwari (West)","SOCIETY_NAME":"Off S.v. Road","PROP_NAME":"Off S.V. Road","LISTING":"P","BEDROOM_NUM":1,"LATITUDE":"19.1364893","LONGITUDE":"72.8488709","PROP_INFO":{"class_label":"Dealer","dealer_url":"\/sainath-estate-mumbai-andheri-dahisar-drid-509882","text":"Sainath Estate","link":true,"vcard":false},"BLDNG_INFO":{"name":"Off S.v. Road","link":null,"label":"Society :","cls":"fwn ","lcls":null},"DEFAULT_THUMB":{"url":"http:\/\/static.99acres.com\/images\/mapsearch\/nophoto.jpg","type":"noPhoto"},"MAPPED":"N","AVAILABILITY":"Ready to Move","FURNISH":""}],"encrypted_input":"UiB8IFFTIHwgUyB8IzIjICB8IG11bWJhaSB8IzMjICB8IE5SSSB8IFkgIzIxI3wgIHwgMSw0LDIsMyw5MCw1LDIyIHwgMTIgfCMxIyAgfCBPLEEsQiMzIyB8IDEsNCwyLDMsOTAsNSwyMiM1IyB8IE8sQSxCICMxMiN8ICB8IDEgfCAxOS4xMzcyMTIyOTQ2ODk1MjIgfCA3Mi44NDc5NjI1ODE3ODcxIHwgMyAjMTQjfCAg","list_vlnk":"\/property-in-mumbai-ffid?orig_property_type=1,4,2,3,90,5,22&class=O,A,B&search_type=QS&search_location=NRI&pageid=QS&keyword_orig=mumbai&property_type=1,4,2,3,90,5,22","html2":"

请提出任何建议? 谢谢..

0 个答案:

没有答案