473,405 Members | 2,160 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,405 software developers and data experts.

deleting line from an array

44
hi guys

i have a problem here it seems like i dont get a solution.i manage to write to the text file but i want to update the existing line without writting a new line.
my problem is when i want to append at the end of a line my programm write at the beginning of a next line.

example

1 (2008_22)-simon; thuli ; tumi
2 (2008_23)-dude ; dan ;

3 dan;tumu(2008_24) -danken ;bobo;

my problem is i want to add : dan and tumi at the end of the second line
not at the begining of the third line.

someone look at my code and help:

Expand|Select|Wrap|Line Numbers
  1.         function write($lineNumbers,$lineNumber)
  2.     {
  3.         if($_POST["cite1"] && $_POST["cite2"] && $_POST["cite3"])
  4.         $data =$_POST["cite1"].";" .$_POST["cite2"].";".$_POST["cite3"];    
  5.  
  6.         $q=$_POST["path"];
  7.  
  8.         $myArray = file($q."Registry.txt");
  9.         //echo "the linenumber is ".$lineNumbers." the line is ". $myArray[$lineNumbers-1]."<br/>";
  10.  
  11.         //Open registry file and wipe contents
  12.  
  13.         $fp = fopen($q."Registry.txt", "w");
  14.         //$myArray[$lineNumbers-1] = $myArray[$lineNumbers-1].$data;
  15.         //echo $myArray[$lineNumbers-1]."<br />";
  16.         $newdata = $myArray[$lineNumbers-1].$data;
  17.         //echo $newdata."<br/>";
  18.  
  19.         // remove the line from a file
  20.         unset($myArray["$lineNumbers-1"]);
  21.         // put the data at the end of my file
  22.         array_push("$myArray","$newdata");
  23.  
  24.         usort($myArray,"strnatcmp");
  25.  
  26.         //Loop through the registry array
  27.  
  28.         foreach ($myArray as $value)
  29.  
  30.         {
  31.  
  32.             //Write the sorted contents to registry line-by-line
  33.  
  34.               fwrite($fp,$value);
  35.  
  36.  
  37.  
  38.     }
  39.  
  40.  
  41.  
  42.         // Close the registry file
  43.  
  44.         fclose($fp);
  45.         echo "the registry updated successfully <br />";
  46.         $myArray1 = file($q."Registry.txt");
  47.         echo "new registry is ".$myArray1[$lineNumbers-1]."<br />";
  48.         echo "line after is ".$myArray1[$lineNumbers]."<br />";                
  49.  
  50.     }
  51.  
  52.  
  53.  
  54.  
  55.  
  56. ?>
Aug 5 '08 #1
1 1192
Ajm113
161 100+
PHP should be like C++, where you can make a while loop then get something like fgets into the while loop and count for each line into a int and get the lines into a string array and if you want to replace a certain line just enter,

array[$iLine--] = "My data goes here."; = Line1, so just minus the id number by one.

For removel just make the line equal nothing in double quotes and make a if statment weather if that line has something or not to break the line or not or even enter the text.

Then get all the arrays representing the line and print them back out into the file like new into each line using that if statment.

I wanted to be a bit of a help, but that should give you a idea what to do.

BTW use the PHP tags please! So its easier to read your code. Its that button with the php page uptop in the editor.
Aug 5 '08 #2

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

Similar topics

5
by: flupke | last post by:
Hi, i'm having trouble with deleting elements from a list in a for loop ============== test program ============== el = print "**** Start ****" print "List = %s " % el index = 0 for line...
18
by: Dan | last post by:
hello, I would to know if it is possible to delete an instance in an array, The following does not allow me to do a delete. I am trying to find and delete the duplicate in an array, thanks ...
0
by: Bandit | last post by:
I'm populating a gridview (called docList) with document info from a network folder like so: Sub Show_Files(ByVal inputDir As String) Dim strFileNamePath As String = inputDir Dim dirInfo As...
46
by: DP | last post by:
hi, i've got a form, with a subform in it. i've got a delete button in the subform. the code i;ve got is; Private Sub cmdDeleteRecord_Click() msg = "Are you sure you want to delete this...
13
by: programming | last post by:
how do i delete from a text file 1 of the following lines: jon|scott adam|smith <--delete paul|clark say i would like to delete the middle line of this txt, in member.txt what php code or...
3
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
One more for today.... As I add more and more lines to my RichTextBox the array that holds its strings gets bigger and bigger and the vertical scroll bar gets smaller and smaller until the...
9
by: n00b | last post by:
Hello everyone, I just had a question about deleting objects in C#. For example if I have a string array and I wanted to make it grow by one size adding the string "dd" to it. string array =...
2
by: helraizer1 | last post by:
Hi folks, I have a file for my chatbox called data.line, which the posts are in the layout CHATBOXTEXT 7 username=helraizer 1202416953
10
by: Faisal Shah | last post by:
HI, Well, Here is the code of my new project .. Actually it's just s scrap or it.. I have made 2 files. the 1st file is test.php with of course creating a new file called testdb.txt. And...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
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
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.