johnmccc Posted June 18, 2010 Share Posted June 18, 2010 Hi I have a simple file.php like this: <?php echo 'Hello'; ?> And I have main PHP script where i want to get the previous file. So i thought must do this: <?php $String = file_get_contents('file.php'); echo $String; ?> But this will print "echo 'Hello';" I want my main PHP file to print "Hello" So the PHP code is not beging processed How can I solve this? I cannot use include or require .. because I want to put the output from file.php into a string! Quote Link to comment https://forums.phpfreaks.com/topic/205157-file_get_contents/ Share on other sites More sharing options...
Adam Posted June 18, 2010 Share Posted June 18, 2010 Take a look around example 5 and 6 area: http://php.net/manual/en/function.include.php Quote Link to comment https://forums.phpfreaks.com/topic/205157-file_get_contents/#findComment-1073848 Share on other sites More sharing options...
johnmccc Posted June 18, 2010 Author Share Posted June 18, 2010 Only the 5th one is working. So if I'm understanding that right my file.php should return something and not echo things? Quote Link to comment https://forums.phpfreaks.com/topic/205157-file_get_contents/#findComment-1073868 Share on other sites More sharing options...
Adam Posted June 18, 2010 Share Posted June 18, 2010 Correct. Quote Link to comment https://forums.phpfreaks.com/topic/205157-file_get_contents/#findComment-1073879 Share on other sites More sharing options...
Adam Posted June 18, 2010 Share Posted June 18, 2010 To add, remember you only return once. Think of the behaviour like a function.. Quote Link to comment https://forums.phpfreaks.com/topic/205157-file_get_contents/#findComment-1073882 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.