473,397 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

manipulating text file

44
hi there! i have a problem manipulating a text file using php. I want to write information posted from an html form. from the example below i want to upload the file and it must be under the specific year and the number must be i sequence. i want the php script to check the year and the number and post the new file under the specific year and number .eg if i upload file 1995_5.rtf it must be written under 1995_4.rtf.


1995_1rtf (8 June 1995) S v m [tty]xs a; 1995 (3) SA otyttt
1995_2.rtf (8 June 1995) S v m [tty]xs a; 1995 (3) SA otyttt
1995_3.rtf (8 June 1995) S v m [tty]xs a; 1995 (3) SA otyttt
1995_4.rtf (8 June 1995) S v m [tty]xs a; 1995 (3) SA otyttt
1996_1.rtf (8 June 1995) S v m [tty]xs a; 1995 (3) SA otyttt
1996_2.rtf (8 June 1995) S v m [tty]xs a; 1995 (3) SA otyttt
1996_3.rtf (8 June 1995) S v m [tty]xs a; 1995 (3) SA otyttt
1996_4.rtf (8 June 1995) S v m [tty]xs a; 1995 (3) SA otyttt
1997_1.rtf (8 June 1995) S v m [tty]xs a; 1995 (3) SA otyttt
1997_2.rtf (8 June 1995) S v m [tty]xs a; 1995 (3) SA otyttt
1997_3.rtf (8 June 1995) S v m [tty]xs a; 1995 (3) SA otyttt
1997_4.rtf (8 June 1995) S v m [tty]xs a; 1995 (3) SA otyttt
Jan 7 '08 #1
3 1526
spudse
11
A small database would be perfect for this. SQLite comes with PHP5 and is quite easy to work with and quick to setup.

Are you experienced with databases? If not, it's not as hard as it seems.
Jan 7 '08 #2
ogo796
44
A small database would be perfect for this. SQLite comes with PHP5 and is quite easy to work with and quick to setup.

Are you experienced with databases? If not, it's not as hard as it seems.

hi,thanks for you'r advice but i am not using the database,i read and write the data to and from the text fie i am using flat file.
Jan 8 '08 #3
spudse
11
I think the easiest way is to make an assiciative array of all lines in the file. First you have to get the files in a variable, file_get_contents() is usefull for this. Then use a regular expression function to get all lines in an array, preg_match_all for instance.

$line [1995] [1] = (8 June 1995) S v m [tty]xs a; 1995 (3) SA otyttt
$line [1995] [2] = (8 June 1995) S v m [tty]xs a; 1995 (3) SA otyttt
...
$line [1997] [4] = (8 June 1995) S v m [tty]xs a; 1995 (3) SA otyttt

And add the new line to the file, with:
Expand|Select|Wrap|Line Numbers
  1. $line[1995][5] = "(8 June 1995) S v m [tty]xs a; 1995 (3) SA otyttt";
Then recreate the contents of the file using foreach(). And use file_put_contents to write the new lines to the file.
Jan 8 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Kristian Nybo | last post by:
Hi, I'm writing a simple image file exporter as part of a school project. To implement my image format of choice I need to work with big-endian bytes, where 'byte' of course means '8 bits', not...
3
by: genc_ ymeri at hotmail dot com | last post by:
Hi, I have some text files and all I need is to look for a certain word a replace it with another one. What is the best way of doing this ? Thank You very much for any tip, G.Y. PS: I'm...
2
by: Ido Flatow | last post by:
Hi all, I've been exploring the way I can manipulate WSDL.exe using SchemaImporterExtension in order to create a proxy to my liking. My situation is as follows - I have a web site that has...
1
by: John | last post by:
Hi We have a staff file in which each record has a text field which has the name & path of the staff's picture (stored externally). Over years we have archived several staff but pictures being...
1
by: kenzoyann6 | last post by:
Good Morning to everyone! My name is Yann! I need to create a s/w in VB.Net 2005, in which I need to manipulate data in a text file; that is I need to store, view, edit and delete data in a text...
3
by: grif | last post by:
hey everyone! In amongst my C# learning i'm starting to fiddle around with some basic code on stuff that interests me. So I decided to write a really simple console app that basically opens and...
1
by: kendrick82 | last post by:
Hi, I would like to seek some advise and assistance regarding the following matter as I am new to VB.Net. I'll appreciate any helps render. I am developing a VB application using VB.Net 2003 to...
1
by: =?utf-8?q?C=C3=A9dric_Lucantis?= | last post by:
Le Wednesday 02 July 2008 01:16:30 Ben Keshet, vous avez écrit : If the file you're reading is not too big, you can use file.readlines() which read all the files and returns its content as a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.