Jump to content

Reading a text file and displaying its contents


Mike D

Recommended Posts

So, I'm trying to get this read my text document "news.txt" and display the contents.

 

My code:

div.newscontent{
padding:0px;
margin-top:60px;
margin-bottom:0px;
margin-left:400px;
margin-right:0px;
position:absolute;
width:457px;
height:330px;
text-align:center;
color:#FFFFFF;	
}

 


<div class='newscontent'>
<?PHP

$filename = "news.txt";
$arr = file($filename);
foreach($arr as $line){
    print $line . "<br/>";
}

?>
</div>

 

This is the output I get:

"; } ?> 

 

Whats wrong? :confused:

Link to comment
Share on other sites

Either your file is not named *.php or PHP is not installed/installed properly.

 

How did you come to that conclusion?

Experience, and from having seen many of these questions in my time.

 

Look at the code as HTML markup, not PHP code: the <?php is the beginning of a tag which doesn't end until the next />. The following

"; } ?>

will be rendered as text - precisely as OP described.

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.