m1tch37 Posted May 17, 2008 Share Posted May 17, 2008 I have a php script located on my server which when viewed has a simple text output, but contains a huge amount of processing. I am trying to read this text output from another page, however, fread, file and file_get_contents all return the PHP code, not the evaluated output. I suppose this makes sense, its just reading the file, but how can I read what you see in a web browser? I can't directly include the file because both are big scripts that are very different, but have many similar variable names. When I include one into another it makes a storm of errors. How can I get around this, by either reading an evaluated php file on my server, or somehow including a page whilst keeping it completely independent besides a string I must read? Thanks. Edit: If i explained it poorly, here is an example: toread.php: <?php print "sunny"; ?> index.php: <?php print "The weather is ".file_get_contents("toread.php"); ?> Expected (desired) Results: The weather is sunny Actual Results: The weather is <?php print "sunny"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/106027-reading-the-output-of-an-evaluated-php-file/ Share on other sites More sharing options...
sasa Posted May 17, 2008 Share Posted May 17, 2008 try <?php print "The weather is ".file_get_contents("http://your_domain/toread.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/106027-reading-the-output-of-an-evaluated-php-file/#findComment-543396 Share on other sites More sharing options...
m1tch37 Posted May 17, 2008 Author Share Posted May 17, 2008 Thank you, that does work. However, I only 'know' the relative path to the file, is there any work around that doesnt require the full path? Thank You, Mitch Quote Link to comment https://forums.phpfreaks.com/topic/106027-reading-the-output-of-an-evaluated-php-file/#findComment-543492 Share on other sites More sharing options...
sasa Posted May 18, 2008 Share Posted May 18, 2008 you can use include() Quote Link to comment https://forums.phpfreaks.com/topic/106027-reading-the-output-of-an-evaluated-php-file/#findComment-543985 Share on other sites More sharing options...
m1tch37 Posted May 18, 2008 Author Share Posted May 18, 2008 I can't directly include the file because both are big scripts that are very different, but have many similar variable names. When I include one into another it makes a storm of errors I can't use include, the example I had was simplified. Whilst not the most elegant solution, I made do with reading the file off the server as you suggested. It shall do for this rough hack. Quote Link to comment https://forums.phpfreaks.com/topic/106027-reading-the-output-of-an-evaluated-php-file/#findComment-544005 Share on other sites More sharing options...
sasa Posted May 18, 2008 Share Posted May 18, 2008 you can put all of your page in function and then imclude it <?php function blah_blah(){ //your page here } blah_blah(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/106027-reading-the-output-of-an-evaluated-php-file/#findComment-544157 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.