0

I want to read a PHP file located on the same server as the script. Yet, I want to read it as if it is from another server so that it views the HTML output of the file.

But when I read the file using file_get_contents() I just get the PHP Code.

NOTE: if this helps, I`m printing the contents of the file to fckEditor.

3
  • What are you passing to file_get_contents()? Commented Nov 20, 2010 at 17:49
  • @Jim Lewis: I`m passing the .php file. Commented Nov 20, 2010 at 17:58
  • I was hoping you'd show the actual line of code. Are you passing it as a pathname, a file: URL, or an http: URL? I'd expect the first two options to return the source code, and the final option to return the HTML output you're looking for. Commented Nov 20, 2010 at 18:04

2 Answers 2

2

use curl

function get_web_page( $url ) { $options = array( CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_ENCODING => "", // handle all encodings CURLOPT_USERAGENT => "spider", // who am i CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects ); $ch = curl_init( $url ); curl_setopt_array( $ch, $options ); $content = curl_exec( $ch ); $err = curl_errno( $ch ); $errmsg = curl_error( $ch ); $header = curl_getinfo( $ch ); curl_close( $ch ); $header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; return $header; } 

$x=get_web_page('http://yourserver/the_script.php');

echo $x["content"];

Sign up to request clarification or add additional context in comments.

Comments

0

You don't need to read it, just include it using include(), for example:

$includefile="path/to/file.php"; if (file_exists($includefile)) include($includefile); 

EDIT:

if you need to assign the output to a variable, use ob_start() and ob_get_clean()

ob_start(); include($includefile); $out = ob_get_clean(); 

Looking at the FCKeditor site, you would use it like this:

$FCKeditor->Value = $out; 

3 Comments

Wimmel: I dont want to include it, I want the user to be able to edit it using the fckEditor. so including the file wont help.
@sikas, I'm not familiar with fckEditor, but I modified my response, hoping that this is what you mean.
the update didn`t work, as there is an included file in both.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.