clarinetmeister
06-21-2010, 10:11 PM
I wrote the following code for my website to read a txt file with news posts and write them to the web page. Each line of the text file is formatted date, time|username|posttitle|postbody. The script splits the text file into an array by line, and then reads each element of the array. It is embedded into the html file, which uses CSS. The final result is supposed to look something like the lower post in this screenshot:
http://dl.dropbox.com/u/3771473/screenshot.jpg
but instead comes out like the upper post in the screenshot. Have I made a syntax error somewhere or something?
<?php
$myFile = "posts.txt";
$lines = file($myFile);
foreach ($lines as &$ln):
echo $ln;
$data = explode ("|", $ln);
?>
<div class='post'><a name='NewMsg'></a><h1><? echo $data[2] ?></h1><p>Posted by: <? echo $data[1] ?></p><p><? echo $data[3] ?></p><p class='post-footer align-right'><a href='index.html' class='readmore'>Read more</a><span class='date'><? echo $data[0] ?></span></p>
<?
endforeach;
?>
Thanks
http://dl.dropbox.com/u/3771473/screenshot.jpg
but instead comes out like the upper post in the screenshot. Have I made a syntax error somewhere or something?
<?php
$myFile = "posts.txt";
$lines = file($myFile);
foreach ($lines as &$ln):
echo $ln;
$data = explode ("|", $ln);
?>
<div class='post'><a name='NewMsg'></a><h1><? echo $data[2] ?></h1><p>Posted by: <? echo $data[1] ?></p><p><? echo $data[3] ?></p><p class='post-footer align-right'><a href='index.html' class='readmore'>Read more</a><span class='date'><? echo $data[0] ?></span></p>
<?
endforeach;
?>
Thanks