doddsey_65 Posted February 13, 2011 Share Posted February 13, 2011 im trying to display the contents of a file within a div. plain html is fine but i need this file to have php variables within it. eg: the file tos.php <?php $foo = 'bar'; ?> <p></php echo $foo; ?></p> the code to display it: file_get_contents(tos.php); but this func only displays the html and doesnt print the contents of anything between php tags. any ideas? Link to comment https://forums.phpfreaks.com/topic/227508-file_get_contents/ Share on other sites More sharing options...
QuickOldCar Posted February 13, 2011 Share Posted February 13, 2011 I'm not sure why you have a forward slash here <p></php echo $foo; ?></p> should be <p><?php echo $foo; ?></p> Link to comment https://forums.phpfreaks.com/topic/227508-file_get_contents/#findComment-1173504 Share on other sites More sharing options...
doddsey_65 Posted February 13, 2011 Author Share Posted February 13, 2011 a typo when posting the topic Link to comment https://forums.phpfreaks.com/topic/227508-file_get_contents/#findComment-1173505 Share on other sites More sharing options...
jcbones Posted February 13, 2011 Share Posted February 13, 2011 Why not just include it. Otherwise, you will have to pass an HTTP request to file_get_contents(). This will only work if fopen wrappers are turned on in your php.ini. Link to comment https://forums.phpfreaks.com/topic/227508-file_get_contents/#findComment-1173507 Share on other sites More sharing options...
lastkarrde Posted February 13, 2011 Share Posted February 13, 2011 $foo = 'bar'; ob_start(); include('tos.php'); $parsedFile = ob_get_contents(); ob_clean(); Link to comment https://forums.phpfreaks.com/topic/227508-file_get_contents/#findComment-1173526 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.