473,657 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

deleting line from an array

44 New Member
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_2 4) -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 1203
Ajm113
161 New Member
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
2731
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 in el:
18
2471
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 for ( j =0; j<MAX ; j++) { for ( i =0; i<MAX ; i++)
0
1405
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 DirectoryInfo = New DirectoryInfo(strFileNamePath) Dim aFiles As FileInfo() = dirInfo.GetFiles("*.doc") Array.Sort(aFiles, New CompareFileInfoEntries (CompareByOptions.LastWriteTime)) docList.DataSource = aFiles
46
4417
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 film rental record?" Style = vbYesNo + vbQuestion + vbDefaultButton2
13
2453
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 logic would help me accomplish this?
3
3737
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 string array finally runs out of memory. I'd like to set some line limit and once that limit is reached, start removing the first line each time a new line is appended onto the end. I think this is probably more of an array manipulation question than...
9
1680
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 = new string {"aa", "bb", "cc"}; string temp = array; array = new string; array = "dd";
2
1486
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
1737
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 the file called admin.php here is the code.
0
8325
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,...
1
8518
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,...
0
8621
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7354
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
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
4173
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
2743
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
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
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.