|
Posted by Jim Michaels on 02/27/06 23:16
"Dalibor" <dalibor_gv@lycos.com> wrote in message
news:fmenawjexnyi$.1gwu27ws1bm56$.dlg@40tude.net...
>I wrote some code for displaying news on my website.
> Code goes like this:
> <?
> $newsfile = 'news.txt';
> echo "<B>TRENUTNE VIJESTI</B><br>\n";
> $data = file($newsfile);
> $data = array_reverse($data);
> echo "<span style=\"normal 11 Verdana; color:#fff;
> text-align:justify;\">";
your CSS needs some help there.
echo "<span style=\"font-family:normal 11 Verdana;font-size:11pt;
color:#fff; text-align:justify;\">";
not sure if the 11 should be in the middle there. is that part of the font
name?
> foreach($data as $element) {
> $element = trim($element);
> $pieces = explode("|", $element);
> echo $pieces[2] . "<BR>" . "<span style=\"font:normal 11px
> Tahoma\"><u>Published</u>: " . $pieces[1] . " " . $pieces[0] .
> "</span></span><BR><br>";
> }
> ?>
> I have form that puts content in flat file.
>
> Messages are writen in flat file in format like this:
> 21.Feb 2006.|Dalibor|Some message text
> 14.Feb 2006.|Dalibor|Other message text...
>
> I need piece of code for displaying last 5 messages and for deleting
> certain messages.
$content=file_get_contents("flatfile.txt");
$content=str_replace("\r\n","\n"); //pc
$content=str_replace("\n\r","\n"); //weird
$content=str_replace("\r","\n"); //mac
//each line as an array element
$arr=split("\n",$content);
for($i=max(0,(count($arr)-1)-5); $i<count($arr); $i++) {
$a=split("|", $arr);
echo "$a[2]\n";
}
to delete an element,
array_splice($arr,$offset,1);
to rewrite the file,
$a=join("\n", $arr);
file_put_contents("flatfile.txt",$a);
> Can you help me? Thanks!
> --
> .:Dalibor:.
Navigation:
[Reply to this message]
|