Go Back   Computer Forums > Web Design | Website Development > Web Programming
Join Computer forums Today

Thread Tools Search this Thread Display Modes
Old 03-30-2004, 10:04 AM   #1
Beta Member
Join Date: Mar 2004
Posts: 2
Default Writing to a file. (PHP)

It's possible to ammend data within a file vs. just adding data to the beginning or the end of the file? Mean to change something in the "middle" of the file.


Nasimov is offline   Reply With Quote
Old 03-30-2004, 10:06 AM   #2
Site Team
David Lindon's Avatar
Join Date: Dec 2002
Posts: 15,233
Default Re: Writing to a file. (PHP)

I am not a PHP expert but I am sure it can be done. You will have to use something like the $curline function in Perl to search for something in the file and edit it.

[url=http://www.LNXPS.NET]LNXPS.NET - The XPS Library]
David Lindon is offline   Reply With Quote
Old 03-30-2004, 06:12 PM   #3
Site Team
root's Avatar
Join Date: Mar 2004
Posts: 7,872

I'm fairly sure you could use a pointer, the file opperations in PHP seem to be very closly linked to those in C...

Failing that you could read the entire string to a variable then use the split() function to remove the dat ayou wanted to keep/put bits in the middle of.

for instance if you wanted to insert a new row into the top of a table in an HTML document, you could do it like this

//open file for reading
$file = "/path/to/file.txt";
$link = fopen($file, "r");
//read file to string
$contents = fread($link, filesize($file));
//get size of string

//split the start of the file after the table tag
//the first half goes to a[0] the second half goes to a[1]
$a = split("<table>", $contents[$line]);
$b = "your_stuff_you_want_to_insert "

//not sure if this string is consturcted right
//if it were asp it be text = a[]0 & yourstring & a[1]
$text = "$a[0] $b $a[1]"

//open file destructive open
$file = "/path/to/file.txt";
$link = fopen($file, "w");
//write string to file
//not sure if this is correct
fwrite($link, $text));

Again i'm sory I've not tested this code before posting it (got many many assignments due). You might have to look some ov the details about how to use functions over in the PHP manual.
But I hoped this suggestion was beter than complete silence!
root is offline   Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

All times are GMT -5. The time now is 10:40 PM.

Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0