How can I use php to call this sina api?

Source: Internet
Author: User
The Sina stock data interface takes Daqin Railway (stock code: 601006) as an example. to obtain its latest stock information, you only need to access Sina stock data interface: hq. sinajs. cnlistsh60... this url returns a string of text, such as varhq_str_sh601006 & quot; Daqin Railway ,... sina stock data interface
Take the Daqin Railway (stock code: 601006) as an example. to get its latest market, you only need to access Sina's stock data interface:

Http://hq.sinajs.cn/list=sh60...

This url returns a string of text, for example:
Var hq_str_sh601006 = "Daqin Railway, 27.55, 27.25, 26.91, 27.55, 26.20, 26.91, 26.92,
22114263,589 listen 680, 4695, 26.91, 57590, 26.90, 14700, 26.89, 14300,
26.88, 15100, 26.87, 3100, 26.92, 8900, 26.93, 14230, 26.94, 25150, 26.95, 15220, 26.96, 15:05:32 ";

How can php get this string?

Reply content:

Sina stock data interface
Take the Daqin Railway (stock code: 601006) as an example. to get its latest market, you only need to access Sina's stock data interface:

Http://hq.sinajs.cn/list=sh60...

This url returns a string of text, for example:
Var hq_str_sh601006 = "Daqin Railway, 27.55, 27.25, 26.91, 27.55, 26.20, 26.91, 26.92,
22114263,589 listen 680, 4695, 26.91, 57590, 26.90, 14700, 26.89, 14300,
26.88, 15100, 26.87, 3100, 26.92, 8900, 26.93, 14230, 26.94, 25150, 26.95, 15220, 26.96, 15:05:32 ";

How can php get this string?

curlAh. Try again

function getCurlData($url) {    if (empty ( $url )) {        return false;    }    $ch = curl_init ();    curl_setopt ( $ch, CURLOPT_URL, $url );    curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );    curl_setopt ( $ch, CURLOPT_HEADER, 0 );    $output = curl_exec ( $ch );    curl_close ( $ch );    return $output;}

We recommend that you use curl

Direct get access. list is the parameter.

Php is not required.《script》You can usehq_str_sh601006Variable. do you want to cache it? It's not necessary at all. Sina has already cached it. it's very fast.

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.