Home > Backend Development > PHP Tutorial > How to call this sina api using php?

How to call this sina api using php?

WBOY
Release: 2016-08-29 08:50:57
Original
1252 people have browsed it

Sina Stock Data Interface
Take Daqin Railway (stock code: 601006) as an example. If you want to get its latest quotes, just visit Sina’s stock data interface:

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

This url will return 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, 589824680, 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, 2008-01-11, 15:05:32";

How can I let php get this string?

Reply content:

Sina Stock Data Interface
Take Daqin Railway (stock code: 601006) as an example. If you want to get its latest quotes, just visit Sina’s stock data interface:

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

This url will return 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, 589824680, 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, 2008-01-11, 15:05:32";

How can I let php get this string?

curlah. Give it a try for reference

<code>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;
}</code>
Copy after login

It is recommended that you use curl

Direct access via get method, list is the parameter

No need for php, just use <script>to import it and use the hq_str_sh601006 variable. Do you want to cache it? There is no need at all, Sina has already cached it. This is already very fast

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template