views:

114

answers:

3

why i not getting return on file_get_contents($myurl) but i do get output for wget

updated:

i use curl to get the return header and result and discovery that the it is on the header instead in of the body

HTTP/1.1 200 Document follows
Transfer-Encoding: chunked
Content-type: text/plain
Server: XMS (724Solutions HTA XSAM_30_M2_B020 20070803.172831)
Date: Fri, 21 May 2010 10:48:31 GMT
Accept-Ranges: bytes

HTTP/1.1 404 ChargedPartyNotAvailable
Transfer-Encoding: chunked
Content-type: text/plain
Server: XMS (724Solutions HTA XSAM_30_M2_B020 20070803.172831)
Date: Fri, 21 May 2010 10:34:13 GMT
Accept-Ranges: bytes

How can i extract out only "200 Document Follow" and "404 ChargedPartyNotAvailable" ?

+1  A: 

You can use PHP Curl package to retrieve the content of URL

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$myUrl);
$result = curl_exec($ch);
curl_close($ch); 

Or if you want to use only file_get_contents, check if you configured PHP.ini correctly

http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

As mentioned here (http://php.net/manual/en/function.file-get-contents.php)

A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename.

Kunal
+1 for curl alternative solution
wimvds
the PHP configuration is ok. it seem it appear only header instead of body
conandor
+3  A: 

Do you have allow_url_fopen enabled in your php configuration?

However I would expect that you would get a warning generated if not - do you have errors/warnings displayed? You could add temporarily at the top of your script :

error_reporting(E_ALL);
ini_set('display_errors', true);

and then you might see why file_get_contents() doesn't work.

Edit

You might just be able to use get_headers() if you're only interested in headers.

Tom Haigh
+1 for allow_url_fopen and the error_reporting suggestion (though I would just log errors :p).
wimvds
no problem with the configuration. it seems that the result is appear in the header not in the body
conandor
@conandor: updated answer based on your edit
Tom Haigh
Yes you are right Tom. I only interested with the headers and mistook file_get_contents($myurl) to get it.
conandor
A: 

you could try:

$contents = implode('', file($myurl));

i use it very often

Mihai Iorga