473,698 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

News script in flat file

I wrote some code for displaying news on my website.
Code goes like this:
<?
$newsfile = 'news.txt';
echo "<B>TRENUTN E VIJESTI</B><br>\n";
$data = file($newsfile) ;
$data = array_reverse($ data);
echo "<span style=\"normal 11 Verdana; color:#fff; text-align:justify;\ ">";
foreach($data as $element) {
$element = trim($element);
$pieces = explode("|", $element);
echo $pieces[2] . "<BR>" . "<span style=\"font:no rmal 11px
Tahoma\"><u>Pub lished</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|S ome message text
14.Feb 2006.|Dalibor|O ther message text...

I need piece of code for displaying last 5 messages and for deleting
certain messages.
Can you help me? Thanks!
--
..:Dalibor:.
Feb 18 '06 #1
5 3028
Dalibor wrote:
I wrote some code for displaying news on my website.
Code goes like this:
<?
$newsfile = 'news.txt';
echo "<B>TRENUTN E VIJESTI</B><br>\n";
$data = file($newsfile) ;
$data = array_reverse($ data);
echo "<span style=\"normal 11 Verdana; color:#fff; text-align:justify;\ ">";
foreach($data as $element) {
$element = trim($element);
$pieces = explode("|", $element);
echo $pieces[2] . "<BR>" . "<span style=\"font:no rmal 11px
Tahoma\"><u>Pub lished</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|S ome message text
14.Feb 2006.|Dalibor|O ther message text...

I need piece of code for displaying last 5 messages and for deleting
certain messages.
Can you help me? Thanks!


writing your own newsreader?

have you looked at http://www.newsportal.one.pl

It even runs on my OpenVMS/Alpha system.

--
Michael Austin.
DBA Consultant
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Feb 18 '06 #2
Use array_slice to extract the last five messages. What constitutes a
"certain" message? Little hard to provide an example when we dont' know
what "certain" equals.

Feb 18 '06 #3
On 17 Feb 2006 20:01:51 -0800, samudasu wrote:
Use array_slice to extract the last five messages. What constitutes a
"certain" message? Little hard to provide an example when we dont' know
what "certain" equals.


Well I ment to have admin page for news, in which will be diplayed all
messages, and after each message i want to be link for deleting that
message.
Like this:
Some message text
By Dalibor on 21.Feb 2006. - Delete
------------
Other message text...
By Dalibor on 14.Feb 2006. - Delete

And when I press delete message is deleted.
--
..:Dalibor:.
Feb 19 '06 #4
This code will delete your messages. It's coded for php5. If you're
running php4 then you'll have to substitute fopen, fwrite, and fclose
for file_put_conten ts.

shownews.php... .......
<?php
$data = file('news.txt' );
foreach ($data as $key => $value) {
print "$value: <a href=\"delnews. php?del=$key\"> delete</a><br
/>\n";
}
?>

delnews.php.... .........
<?php
$file = 'news.txt';
$data = file($file);
unset($data[$_GET['del']]);
print "<pre>";
print_r($data);
print "</pre>";
file_put_conten ts($file, $data);
?>

Feb 19 '06 #5
I did it! Thanks everybody for hellping me!
--
..:Dalibor:.
Feb 23 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
3419
by: raykyoto | last post by:
Hi all, I'm sure this is a popular question that comes up every few months here. Indeed, I've looked at some of the past postings, but I would like to ask things differently. Basically, I'm using a flat file to storing data. I have to do this because mySQL is not installed on my web server, and I am not the root user. The amount of data is so small, that it isn't worth a full-blown database anyway. However, while the data is...
9
2188
by: FFMG | last post by:
In my site I have a config table, (MySQL), with about 30 entries; the data is loaded on every single page load. This is not the only call to the db, (we do a total of about 8 calls to the db). As with many configurations settings, once the options are set the values will not change much. So I thought it would be a good idea to move the data to a flat file. I have written a small wrapper class to first look for the file, if it exists...
2
2003
by: Susanne West | last post by:
hi group. i'm tackling a bigger project that will use mod_rewrite to patch a series of urls into a master php-script. this script builds the page framework that contains a series of elements that remain on every page. only a center part (a <div>) is filled with different contents, depending on how the page is called (= mode of the page). the point is, there are quite a few (approx 20) different 'modes' for the center part to be filled...
3
2108
by: pnsreee | last post by:
Hi All, I am trying to print a log file created in the same script with the code bellow. but Im not getting output on screen. The output file is created using rediretion of output. open(STDOUT, ">flat.log") || die "Can't redirect stdout"; prinf " ----------------------------------------------\n";
5
1944
by: deppeler | last post by:
Can someone look at this for me: I am trying to set up a script to edit an item in a flat file DB but I don't seem to be getting the data to the Photoedit script. It seems to be reading the 1st line of the DB and not what is selected. I am all messed up..I know this is straight forward but I am having a real hard time with this. I am wanting the user to be able to select a photo (nfile_name - radio button) and if desired alter the text...
2
6135
by: murthydb2 | last post by:
Hi My requirement is that i have to write a stored procedure in db2 and that will be executed in a batch file . Any system error or validation error that occurs inside the db2 sp during the execution need to be written in external flat file ( Log file to know the error ) . Is there anything similar in db2 like UTL_FILE in oracle . Please find the sample coding in oracle which will write the output to a external flat...
3
6441
by: techquest | last post by:
Hi, I want to connect into oracle database and export the table data into a flat file using UNIX shell scripts. I cant use other GUI tools to do this, as the dataload will be in millions. hence if i try to export from toad/sqlplus its hanging. And also i need to some validation using UNIX. So please give me some tip to write a script which does this operation. Req: 1) Connect oracle 2) Select * from employee 3) Write into some flat...
15
5269
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to show - text boxes, input boxes, buttons, hyperlinks ie the usual. The data is not obtained directly from a database.
3
3729
by: Okonita via DBMonster.com | last post by:
Hi all, Working on a little shell script to remove specific records from a flat file. I have scanned a one or two script books and googled for answers but have no success. Can someone show me how I can do this. For example, how can I remove the something like the following records from among 200 other records: DB2ADMIN.EPISODE_1; DB2ADMIN.EPISODE_2; DB2ADMIN.EPISODE_3; DB2ADMIN.EPISODE_4; DB2ADMIN.EPISODE_5;
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8610
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.