file-get-contents

PHP: file_get_contents failed to open stream: Connection refused

人盡茶涼 提交于 2019-12-02 05:34:38
问题 I am trying to access a second server with file_get_contents and simple_load_xml and I get "failed to open stream: Connection refused" What can be the result? allow_url_fopen=Yes allow_url_include=Off is my php.ini values 回答1: Sounds like the 2nd server is rejecting the file, try using curl to obtain the file instead; the benefit of using curl is that it'll give you helpful debugging information in the event of a failure like this. get_file_content() masks a lot of this helpful information.

file_get_contents() fails with special characters in URL

邮差的信 提交于 2019-12-02 05:09:53
问题 I have a need to fetch some URL's which have some characters from the Swedish alphabet. If you take an example of such string as https://en.wikipedia.org/wiki/Åland_Islands , passing that straight into the file_get_contents call as a parameter works just fine. But if you run that URL through urlencode first, then the call fails with the message: failed to open stream: No such file or directory despite the documentation for file_get_contents saying: Note: If you're opening a URI with special

PHP file_get_contents - Replace all URLs in all <a href=“”> links

喜夏-厌秋 提交于 2019-12-02 04:23:25
SOLVED: Answer Below HOW TO: - Get all the urls from a file pulled using file_get_contents. The file can by dynamic and have multiple URLs - Replace all urls with custom A NEW URL and add the existing current url on the end as a Variable Example: Change the link www.ABC.com to www.MyWebsite.com/?link=www.ABC.com FILE NAME: myHTML.html The HTML email that will be pulled using file_get_contents <body> <p> </p> <p><a href="http://www.CNN.com" target="_blank">Link One</a></p> <p><a href="http://www.ABC.com" target="_blank">Link Two</a></p> <p><a href="http://www.foxnews.com/politics/2013/01/28/us

file_get_contents not extracting full file contents

陌路散爱 提交于 2019-12-02 03:17:07
I m using the php function file_get_contents to parse a php file. But it seems that as soon as it is reading the php tags the file_get_contents is malfunctioning. I checked the function with a normal text file, its functioning perfectly. But even if it finds php tags in a text file, the file is being half read. How can i find a way to get the full contents. Is the file local? Or are you trying to get a remote file? How did you check that the content is not read? Echoing it to a browser might trick you because of the < char in <?php Use htmlspecialchars or <pre> to view the whole text. Or just

file_get_contents php and json_decode error

孤者浪人 提交于 2019-12-02 02:22:23
问题 I am facing a weird problem with file_get_contents and decoding to json the result. I have to tell you that this code was fully functional in other server. I am trying to decode this json: http://mediarupt.com/GET/categorized_services_for_supplier.php?suppliersID=10 into this page: http://mediarupt.com/kostas.php The code for kostas.php is this: <?php $servicesJSON = file_get_contents("http://mediarupt.com/GET/categorized_services_for_supplier.php?suppliersID=10"); $ForeignKeys = (object

PHP: file_get_contents failed to open stream: Connection refused

心已入冬 提交于 2019-12-02 02:17:46
I am trying to access a second server with file_get_contents and simple_load_xml and I get "failed to open stream: Connection refused" What can be the result? allow_url_fopen=Yes allow_url_include=Off is my php.ini values Sounds like the 2nd server is rejecting the file, try using curl to obtain the file instead; the benefit of using curl is that it'll give you helpful debugging information in the event of a failure like this. get_file_content() masks a lot of this helpful information. Your connection to the resource is being rejected. Ensure that you can access the resource from the server

Nginx and PHP-cgi - can't file_get_contents of any website on the server

我是研究僧i 提交于 2019-12-02 00:12:45
This one is best explained by code I think. From the web directory: vi get.php Add this php to get.php <? echo file_get_contents("http://IPOFTHESERVER/"); ?> IPOFTHESERVER is the IP of the server that nginx and PHP are running on. php get.php Returns the contents of the (default) website hosted at that I.P. BUT http://IPOFTHESERVER/get.php ..returns a 504 Gateway Time-out . It's the same with curl. It's the same using the PHP exec command and GET. However, from the command line directly it all works fine. I've replicated it on 2 nginx servers. For some reason nginx won't allow me to make an

Getting garbage output when scraping a webpage in PHP

情到浓时终转凉″ 提交于 2019-12-01 21:38:07
I am trying to get the contents of a page from Amazon using file_get_html() but the output comes with weird characters on echo . Can anyone please explain how can I resolve this issue? I also found the following two related questions on Stack Overflow but they did not solve my issue. :) file_get_html() returns garbage Uncompress gzip compressed http response Here is my code: $options = array( 'http'=>array( 'header'=> "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n". "Accept-language: en-US,en;q=0.5\r\n" . "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US

HTTP request failed! HTTP/1.1 503 Service Temporarily Unavailable

前提是你 提交于 2019-12-01 18:22:49
问题 I am using function file_get_contents to get contents from web page. Some website working well but most of them give me this error failed to open stream: HTTP request failed! HTTP/1.1 503 Service Temporarily Unavailable Here is my simple code echo file_get_contents("url"); When i run this url in browser it works fine.what can be the issue? 回答1: 503 means the functions are working and you're getting a response from the remote server denying you. If you ever tried to cURL google results the

file_get_contents: get full response even on error

有些话、适合烂在心里 提交于 2019-12-01 18:12:42
Is it possible to make file_get_contents show me the actual response even if an error occurs? It is difficult to debug otherwise. For instance, say you have the following code: $url = 'https://api.twitter.com/oauth/request_token'; $data = array(); $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data), ), ); $context = stream_context_create($options); $result = @file_get_contents($url, false, $context); var_dump($result); var_dump($http_response_header); This shows me NULL for the result and