PHP file_get_contents() returns “failed to open stream: HTTP request failed!”

前端 未结 11 920
名媛妹妹
名媛妹妹 2020-11-22 13:03

I am having problems calling a url from PHP code. I need to call a service using a query string from my PHP code. If I type the url into a browser, it works ok, but if I use

11条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 13:37

    I got a similar problem , I parsed the youtube url. The code is;

    $json_is = "http://gdata.youtube.com/feeds/api/videos?q=".$this->video_url."&max-results=1&alt=json";
    $video_info = json_decode ( file_get_contents ( $json_is ), true );     
    $video_title = is_array ( $video_info ) ? $video_info ['feed'] ['entry'] [0] ['title'] ['$t'] : '';
    

    Then I realise that $this->video_url include the whitespace. I solved that using trim($this->video_url).

    Maybe it will help you . Good Luck

提交回复
热议问题