doddsey_65 Posted December 13, 2010 Share Posted December 13, 2010 is there a way to print the file as it appears. I want to print the HTML and PHP within a file rather than just the output. Example: File contains: <?php echo "Hello World"; ?> i would like to echo: <?php echo "Hello World"; ?> instead of just hello world which is what i get with file_get_contents() Quote Link to comment https://forums.phpfreaks.com/topic/221477-print-exact-file-contents/ Share on other sites More sharing options...
laffin Posted December 13, 2010 Share Posted December 13, 2010 Plenty of ways of doing this I'll give u 2 1) <? header('Content-Type: text/plain'); readfile('file.name'); note: that the use of header and content type, means this file is of that type, so u cant mix this with html. 1) <? $contents=htmlspecialchars(file_get_contents('file.name')); Echo $contents; using htmlspecialchars, to convert html/xml/php/etc file to html encoded file, where html special characters are converted to their meta equivalents, < becomes < Quote Link to comment https://forums.phpfreaks.com/topic/221477-print-exact-file-contents/#findComment-1146523 Share on other sites More sharing options...
PFMaBiSmAd Posted December 13, 2010 Share Posted December 13, 2010 highlight_file or highlight_string Quote Link to comment https://forums.phpfreaks.com/topic/221477-print-exact-file-contents/#findComment-1146563 Share on other sites More sharing options...
salathe Posted December 13, 2010 Share Posted December 13, 2010 instead of just hello world which is what i get with file_get_contents() How are you calling file_get_contents()? The function will not evaluate PHP code, it simply fetches the content of the file (or output of an URL) and nothing else. Quote Link to comment https://forums.phpfreaks.com/topic/221477-print-exact-file-contents/#findComment-1146566 Share on other sites More sharing options...
doddsey_65 Posted December 15, 2010 Author Share Posted December 15, 2010 thanks for the replies. I managed to solve it with highlight_string(). Does anyone know, however, if there is a function to highlight the html as well as php files? Or am I looking at adding the possible tags into arrays as keys with their respective colors as values? Quote Link to comment https://forums.phpfreaks.com/topic/221477-print-exact-file-contents/#findComment-1147566 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.