0

基本上这是一个搜索栏,我将搜索到的术语放在 api 调用 url 中,但是我得到了

警告:simplexml_load_file() [function.simplexml-load-file]:I/O 警告:未能加载外部实体“”

有任何想法吗?

代码:

if (!empty($_POST['searchbird'])){
    $searchbird=rawurlencode($_POST['searchbird']);
    $searchCode = "http://ebird.org/ws1.1/data/obs/region_spp/recent?rtype=subnational2&r=US-AZ-013&sci=$searchbird";
    $url_headers = @get_headers($searchCode);

    if($url_headers[0] == 'HTTP/1.1 200 OK') {
        $xml = simplexml_load_file($url);

        print_r($xml);

    } else {
        // Error
        echo $searchCode;
        print_r($url_headers);
        exit("failed to load XML");
    }


} else {
    $searchbird = '';
    $form = "<form method='post'>
       <strong>Enter the name of a Bird</strong>
       <input type='text' name='searchbird' value='$searchbird' />
       <input type='submit' name='submit' value='submit' />
    </form>";
    echo $form;
}
4

1 回答 1

0

您想将函数中的变量从更改$url为,$searchCode因为该$url变量为空且未在任何地方设置。

if (!empty($_POST['searchbird'])){
    $searchbird=rawurlencode($_POST['searchbird']);
    $searchCode = "http://ebird.org/ws1.1/data/obs/region_spp/recent?rtype=subnational2&r=US-AZ-013&sci=$searchbird";
    $url_headers = @get_headers($searchCode);

    if($url_headers[0] == 'HTTP/1.1 200 OK') {
        $xml = simplexml_load_file($searchCode);

        print_r($xml);
 ....
于 2013-04-02T03:11:45.923 回答