file-get-contents

How to execute and get content of a .php file in a variable?

人盡茶涼 提交于 2019-11-27 21:18:18
I want to get contents of a .php file in a variable on other page. I have two files, myfile1.php and myfile2.php . myfile2.php <?PHP $myvar="prashant"; // echo $myvar; ?> Now I want to get the value echoed by the myfile2.php in an variable in myfile1.php, I have tried the follwing way, but its taking all the contents including php tag () also. <?PHP $root_var .= file_get_contents($_SERVER['DOCUMENT_ROOT']."/myfile2.php", true); ?> Please tell me how I can get contents returned by one PHP file into a variable defined in another PHP file. Thanks You can use the include directive to do this. File

Parse html table using file_get_contents to php array

耗尽温柔 提交于 2019-11-27 19:10:41
I am trying to parse the table shown here into a multi-dimensional php array. I am using the following code but for some reason its returning an empty array. After searching around on the web, I found this site which is where I got the parseTable() function from. From reading the comments on that website, I see that the function works perfectly. So I'm assuming there is something wrong with the way I'm getting the HTML code from file_get_contents(). Any thoughts on what I'm doing wrong? <?php $data = file_get_contents('http://flow935.com/playlist/flowhis.HTM'); function parseTable($html) { //

Alternative to file_get_contents?

限于喜欢 提交于 2019-11-27 18:58:54
$xml_file = file_get_contents(SITE_PATH . 'cms/data.php'); The problem is that a server has URL file-access disabled. I cannot enable it, its a hosting thing. So the question is this. The data.php file generates xml code. How can I execute this and get the xml data without doing the above method? Is it possible? The Pellmeister Use cURL . This function is an alternative to file_get_contents . function url_get_contents ($Url) { if (!function_exists('curl_init')){ die('CURL is not installed!'); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $Url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,

file_get_contents - Special characters in URL - Special case

与世无争的帅哥 提交于 2019-11-27 16:21:26
I'm not getting file_get_contents() to return the page in this particular case where the url contains an 'Ö' character. $url = "https://se.timeedit.net/web/liu/db1/schema/s/s.html?tab=3&object=CM_949A11_1534_1603_DAG_DST_50_ÖVRIGT_1_1&type=subgroup&startdate=20150101&enddate=20300501" print file_get_contents($url); How do I make file_get_contents() work as expected on this url? I have tried following solutions whithout a working result: 1. print rawurlencode(utf8_encode($url)); 2. print mb_convert_encoding($url, 'HTML-ENTITIES', "UTF-8"); 3. $url = urlencode($url); print file_get_contents($url

Loading a remote xml page with file_get_contents()

烂漫一生 提交于 2019-11-27 16:13:44
问题 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

How to get results from the Wikipedia API with PHP?

走远了吗. 提交于 2019-11-27 15:24:11
I'm probably not supposed to use file_get_contents() What should I use? I'd like to keep it simple. Warning: file_get_contents(http://en.wikipedia.org/w/api.php?action=query&titles=Your_Highness&prop=revisions&rvprop=content&rvsection=0): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden The problem you are running into here is related to the MW API's User-Agent policy - you must supply a User-Agent header, and that header must supply some means of contacting you. You can do this with file_get_contents() with a stream context : $opts = array('http' => array( 'user_agent' =>

PHP file_get_contents does not work on localhost

梦想的初衷 提交于 2019-11-27 15:09:23
I am working on my website from localhost (http://172.16.65.1/) a MAMP server on OSX. I want to load some JSON from Google and some simple tests show me I have a problem here.. echo file_get_contents("http://www.google.com"); // FAILS // PHP log: [07-Dec-2011 23:09:21] PHP Warning: file_get_contents(http://www.google.com) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: Host is down in /Applications/MAMP/htdocs/-tests/get-json.php on line 3 echo file_get_contents("http://www.yahoo.com"); // FAILS // echo file_get_contents("http://localhost"); //

PHP Get Content of HTTP 400 Response

自作多情 提交于 2019-11-27 14:26:32
I am using PHP with the Amazon Payments web service. I'm having problems with some of my requests. Amazon is returning an error as it should, however the way it goes about it is giving me problems. Amazon returns XML data with a message about the error, but it also throws an HTTP 400 (or even 404 sometimes). This makes file_get_contents() throw an error right away and I have no way to get the content. I've tried using cURL also, but never got it to give me back a response. I really need a way to get the XML returned regardless of HTTP status code. It has an important "message" element that

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

喜你入骨 提交于 2019-11-27 14:15:49
问题 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

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

廉价感情. 提交于 2019-11-27 08:27:21
问题 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