GuitarGod Posted November 7, 2008 Share Posted November 7, 2008 I'm using file_get_contents to call up my HTML files, but sometimes some of these HTML file contain PHP in short tag for, example: <html> <title><?= $page_title; ?></title> etc .... The only problem is that all my PHP tags are ignored, probably because file_get_contents doesn't parse the PHP. Any solution to this? Better yet, a solution where I could still use file_get_contents? I tried looking into using an eval function but didn't really know much about it. Any advice is appreciated. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 7, 2008 Share Posted November 7, 2008 you should use inlcude() if you want the files parsed Quote Link to comment Share on other sites More sharing options...
GuitarGod Posted November 7, 2008 Author Share Posted November 7, 2008 I know, and usually I would use include, but there's a reason why this time I'm using file_get_contents, it's a long story so I won't go into it, but a solution where I could still use this would be great Quote Link to comment Share on other sites More sharing options...
Adam Posted November 7, 2008 Share Posted November 7, 2008 You could use regular expressions to extract everything between PHP tags and then eval the code..? But I'd stored the files in an unaccessible location just for a lil' security - ie. not in 'htdocs' .. Adam Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 7, 2008 Share Posted November 7, 2008 eval(file_get_contents('filename.php')) should work too Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 7, 2008 Share Posted November 7, 2008 LOL, beaten to the post. Eval assumes that the code it is passed is or at leasts starts with php code. If the file starts with HTML, then you need to prepend a closing ?> tag to drop eval() out of php "mode". Actually, since a file would have an opening <?php tag if it started with php code, you could always prepend a closing ?> tag anytime you get code from a file. Quote Link to comment Share on other sites More sharing options...
GuitarGod Posted November 7, 2008 Author Share Posted November 7, 2008 Could you give me an example? Sorry to ask but I've never used eval() before and the PHP website isn't much help in that department. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 7, 2008 Share Posted November 7, 2008 i think he means like this: eval('?>'.file_get_contents('filename.php').'<?php'); Quote Link to comment Share on other sites More sharing options...
GuitarGod Posted November 7, 2008 Author Share Posted November 7, 2008 I tried that but I get an unexpected end error ??? *EDIT* Sorry I copied your example wrong, it works fine. Thanks for the help guys I owe you all Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 7, 2008 Share Posted November 7, 2008 my bad, use: eval('?>'.file_get_contents('user.php')); Quote Link to comment 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.