Curl PHP Script Example

Source: Internet
Author: User

On the Internet to write the data wrote a need for PHP curl function, call is Baidu API get data: function GetData ($add) {

$post _data = Array (' AK=KKKK ', ' callback=renderoption ', ' Output=json ', ' city=xxx, ' address= '. $add); Parameter assembly of the transmission

Print_r ($post _data);

$post _data = Implode (' & ', $post _data);

$url = ' http://api.map.baidu.com/geocoder/v2/? '; Route assembly, the parameters you need do not need to be put here, the above assembly is OK.

Here is some initialization of curl, see PHP manual here.

$ch = Curl_init ();

curl_setopt ($ch, Curlopt_post, 1);

curl_setopt ($ch, Curlopt_url, $url);

curl_setopt ($ch, Curlopt_postfields, $post _data);

Ob_start ();

Curl_exec ($ch); Perform Curl

$result = Ob_get_contents (); Get content

Ob_end_clean ();

Return Json_decode ($result)->result->location;

}

Curl PHP Script Example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.