file-get-contents

Loading a remote xml page with file_get_contents()

微笑、不失礼 提交于 2019-11-29 01:49:22
I have seen some questions similar to this on the internet, none with an answer. I want to return the source of a remote XML page into a string. The remote XML page, for the purposes of this question, is: http://www.test.com/foo.xml In a regular webbrowser, I can view the page and the source is an XML document. When I use file_get_contents('http://www.test.com/foo.xml') , however, it returns a string with the corresponding URL. Is there to retrieve the XML component? I don't care if it uses file_get_contents or not, just something that will work. Seb You need to have allow_url_fopen set in

file_get_contents() converts UTF-8 to ISO-8859-1

為{幸葍}努か 提交于 2019-11-28 22:08:52
I am trying to get search results from yahoo.com . But file_get_contents() converts UTF-8 charset (charset, that yahoo uses) content to ISO-8859-1. Try: $filename = "http://search.yahoo.com/search;_ylt=A0oG7lpgGp9NTSYAiQBXNyoA?p=naj%C5%A1%C5%A5astnej%C5%A1%C3%AD&fr2=sb-top&fr=yfp-t-701&type_param=&rd=pref"; echo file_get_contents($filename); Scripts as header('Content-Type: text/html; charset=UTF-8'); or <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> or $er = mb_convert_encoding($filename , 'UTF-8'); or $s2 = iconv("ISO-8859-1","UTF-8",$filename ); or echo utf8_encode

How do I use file_get_contents to get a gzip'ed page on a remote web server in php?

孤者浪人 提交于 2019-11-28 14:28:57
I'm trying to receive a gzip'ed version of a page through file_get_contents in php 5.2.9 I was able to do it using fopen with the following code: $opts = array( 'http'=>array( 'method'=>"GET", 'header'=>"Accept-language: en\r\n" . "Accept-Encoding: gzip\r\n" ) ); $context = stream_context_create($opts); ob_start(); $fp = fopen('http://example.com', 'r', false, $context); fpassthru($fp); fclose($fp); $content = ob_get_contents(); ob_end_clean(); That works, but I was hoping there was a way I could do it using file_get_contents instead. Thanks. Have you tried this? $content = file_get_contents(

PHP sending variables to file_get_contents()

喜夏-厌秋 提交于 2019-11-28 13:25:23
I want to be able to send a few variables to a file through file_get_contents() . This is firstfile.php: <?php $myvar = 'This is a variable'; // need to send $myvar into secondfile.php $mystr = file_get_contents('secondfile.php'); ?> This is secondfile.php: The value of myvar is: <?php echo $myvar; ?> I want the variable $mystr to equal 'The value of myvar is: This is a variable' Is there any other function that will let you do this in PHP? There is a big difference between getting the contents of a file and running a script : include — this PHP directive runs the specified file as a script ,

GET Request from PHP using file_get_contents with parameters

核能气质少年 提交于 2019-11-28 13:23:53
I want to send a GET request to an external site, but also want to send some parameters for example i've to send a get request to example.com i want to execute www.example.com/send.php?uid=1&pwd=2&msg=3&phone=3&provider=xyz My code is : $getdata = http_build_query( array( 'uid' => '1', 'pwd' => '2', 'msg'=>'3', 'phone'=>'9999', 'provider'=>'xyz' ) ); $opts = array('http' => array( 'method' => 'GET', 'content' => $getdata ) ); $context = stream_context_create($opts); $result = file_get_contents('http://example.com/send.php', false, $context); I get a server error . The content option is used

Remotely download a file from an external link to my server - download stops prematurely

别等时光非礼了梦想. 提交于 2019-11-28 12:54:24
I have a page set where I enter the url of an file and I have my server download that file and save it into a folder on my server. The issue is that I dont know how to download a file to my server. I have tried both of the following methods, and they both didn't work. This one throws an error about a failed open stream: $url = 'http://www.example.com/file.zip'; $enc = urlencode($url); $dir = "/downloads/file.zip"; $raw = file_get_contents($enc); file_put_contents($dir, $raw); This one works but I only get 18kb out of a 270kb file: ( I have tried to increase the timeout) set_time_limit(0); $url

what are the alternatives for php://input and $HTTP_RAW_POST_DATA when file_get_contents and always_populate_raw_post_data are disabled

我的梦境 提交于 2019-11-28 12:39:02
My hosting comp has disabled all the socket functionality except curl. They are so irresponsible on my questions for enabling it. i can think of another hosting yet i want to know the following. I have asked a question related to this and this is a continuation yet another question. I am unable to use file_get_contents('php://input') and always_populate_raw_post_data is disabled in php.ini so i cannot use $HTTP_RAW_POST_DATA. So what is or are the alternatives to get a raw post data. For example i have setup notifications callback url with facebook. so when ever there is an event then facebook

using file get contents or curl

混江龙づ霸主 提交于 2019-11-28 11:57:02
I was ask to use a simple facebook api to return the number of likes or shares at work which return json string. Now since i am going to do this for a very large amount of links, which one is better: Using file_get_contents or cURL. Both of them seem to return the same results and cURL seems to be more complicated to use, but what is the difference among them. why do most people recommend using cURL over file_get_contents? Before i run the api which might take a whole day to process, i will like to have feedback. A few years ago I benchmarked the two and CURL was faster. With CURL you create

Google Analytics API V3 - HTTP Error: Unable to connect on live server (localhost works fine)

送分小仙女□ 提交于 2019-11-28 11:39:11
问题 (I am using the latest version of this library: https://github.com/google/google-api-php-client) In short, my script works perfectly on localhost, but whenever I upload to our production or staging environments it fails. I am now using a really simple test script from this tutorial: http://blog.salteh.net/2012/10/google-analytics-api-and-service-accounts/ Again, this works perfectly on localhost, but errors on our production and staging servers. The error is: HTTP Error: Unable to connect

Storing the HTML output from a local PHP file into a string using file_get_contents

依然范特西╮ 提交于 2019-11-28 11:39:03
There is a header.php file and it contains some php codes that return HTML. I know I can use require, include to echo the results, but what I want to do is to store its processed output string into a variable. In a page, I used: $headerHTML=file_get_contents('header.php'); Then I got the PHP code output rather than the processed HTML output. I know adding http:// would help. But I prefer to keep using relative path, how can I tell the function to treat the php file correctly? Note: I would like to continue to use this statement file_get_contents rather than using ob_start() if possible. I'd