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() 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 < 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 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. 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? Link to comment https://forums.phpfreaks.com/topic/221477-print-exact-file-contents/#findComment-1147566 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.