rhyspaterson Posted May 29, 2007 Share Posted May 29, 2007 Hey guys. I have a file that i open with fopen a+, meaning when i open the file it places the pointer at the end of the file and writes from there. I then write an array to the file. My only problem is, when i place the pointer at the end of the file it looks like this. <bt>600</bt> <iregno>123456789</iregno> <users> <un>1</un> <u1> <n>username1</n> <ema>[email protected]<ema> <s>password</s> <t>status</t> <p>profile name</p> <cat>000000000000000000000000000000000</cat> </u1> </users><<<<< ------ pointer is here and then when i append my data, file looks like this <bt>600</bt> <iregno>123456789</iregno> <users> <un>2</un> <u1> <n>username</n> <ema>[email protected]<ema> <s>password</s> <t>status</t> <p>profile name</p> <cat>000000000000000000000000000000000</cat> </u1> </users><u2> <n>username2</n> <ema>[email protected]<ema> <s>password</s> <t>status</t> <p>profile name</p> <cat>000000000000000000000000000000000</cat> </u2> </users> the bad part being </users><u2> i would like to overwrite the last line and continue adding my data. Is this possible in any way? Thanks so much, /Rhys Link to comment https://forums.phpfreaks.com/topic/53411-solved-fopen-and-a/ Share on other sites More sharing options...
ToonMariner Posted May 29, 2007 Share Posted May 29, 2007 this look smore like a prime candidate for an xml file you can at the very least use the same methods for managing this file have a look at simplexml if you are using php 5 or DOMxml for php4... Link to comment https://forums.phpfreaks.com/topic/53411-solved-fopen-and-a/#findComment-263892 Share on other sites More sharing options...
rhyspaterson Posted May 29, 2007 Author Share Posted May 29, 2007 thats what i told my boss, but based on what they are using, it *has* to be a .txt file.. Link to comment https://forums.phpfreaks.com/topic/53411-solved-fopen-and-a/#findComment-263894 Share on other sites More sharing options...
rhyspaterson Posted May 29, 2007 Author Share Posted May 29, 2007 it looks like fseek is the way to go, but i am just not quite sure how to implement it.. /edit figured it out. $fp = fopen($local_file, "r+") or die ("Can't open user file"); fseek($fp, -8, SEEK_END); foreach($userArray as $val) { fwrite($fp, $val); } fclose($fp); thanks lads. Link to comment https://forums.phpfreaks.com/topic/53411-solved-fopen-and-a/#findComment-263906 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.