Jump to content

print exact file contents


doddsey_65

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.