473,387 Members | 1,504 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,387 software developers and data experts.

updating the registry

44
hi everyone i have a problem with updating the text file
i want to add name at the end of a line and separate with semi colon,
can someone look at my code and help me out.

2004 (12 November 2004) name tumi; yale;
2004 (12 November 2004) name simon; tiro;
2004 (12 November 2004) name lebo; dud ;
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4.  
  5.  
  6.     $data =$_POST["name1"]." " .$_POST["name2"]."; ".$_POST["name3"]." \n";    
  7.  
  8.     $q=$_POST["path"];
  9.  
  10.  
  11.     $myArray = file($q."myfile.txt");
  12.  
  13.  
  14.  
  15.     $fp = fopen($q."Registry.txt", "w");
  16.  
  17.  
  18.     array_push($myArray,$data);
  19.  
  20.  
  21.     usort($myArray,"strnatcmp");
  22.  
  23.  
  24.  
  25.     //Loop through the registry array
  26.  
  27.     foreach ($myArray as $value)
  28.  
  29.     {
  30.  
  31.         //Write the sorted contents to registry line-by-line
  32.  
  33.           fwrite($fp,$value);
  34.  
  35.  
  36.  
  37.     }
  38.  
  39.  
  40.  
  41.     // Close the registry file
  42.  
  43.     fclose($fp);
  44.  
  45.  
  46.  
  47. ?>
  48.  
Aug 1 '08 #1
2 1215
dlite922
1,584 Expert 1GB
[PHP]<?php

# GET DATA
if(!(isset($_POST['name1']) && isset($_POST['name2']) && isset($_POST['name3'])))
{
die("Error: One of the names were not passed via POST.");
}
$data = $_POST["name1"]." " .$_POST["name2"]."; ".$_POST["name3"]." \n";



# GET PATH
if(!isset($_POST['path']))
{
die("Error: Path variable is not set.");
}
$q = $_POST["path"];



# GET MYFILE
if(!$myFile = file($q."myfile.txt"))
{
die("Error: Unable to open file 'myfile.txt'. Please check path and permission");
}



# PUT DATA AT THE END OF MYFILE
array_push($myFile,$data);



# GET REGISTRY FILE
if(!$registryFile = fopen($q."Registry.txt", "w"))
{
die("Error: Unable to open file 'Registry.txt'. Please check path and permission");
}



# SORT MYFILE LINES BY NATURAL ORDER
usort($myFile,"strnatcmp");



# APPEND MY FILE TO REGISTRY FILE
foreach ($myFile as $line)
{
if(!fwrite($registryFile,$line))
{
die("Error: Unable to write to ");
}
}


# CLOSE THE FILES
fclose($registryFile);
fclose($myFile);


# RESULT
echo "Successful.";

?> [/PHP]
Aug 1 '08 #2
ogo796
44
hi there thanks for your answer it works,but i want to add the names at the end of a line separated by semicolon see the example below.

example

2004 (12 November 2004) names Simon; Tiro ; John ;Rebecca;
Aug 4 '08 #3

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

Similar topics

4
by: Sky Fly | last post by:
Hello all, I've written a stored procedure which runs OK for the first few thousand records it processes, then around about the 10,000th record it suffers a sudden and dramatic drop in...
2
by: SomeDude | last post by:
Lo group, I would like to know if it is possible to a (string) replace on existing records based on a given pattern. Let's say I have a table containing the following records (strings):...
2
by: LCD | last post by:
Here is what I want to do: Presently in my registry I have: (Default) = "C:\Program Files\myApp" and this value is scattered all over registry in several keys and subkeys. I wouldlike to...
2
by: Eric Sykes | last post by:
After installing VSNet for several reasons I had to restore the system to before the VSNet installation. I reinstalled VSNet no problem but now when I open up VSNet a message pops up saying "Help...
2
by: jeffrey.bigham | last post by:
Hello, I'm developing an application in C# using the WebBrowser control and need to toggle images off and on. After some digging, I found the appropriate registry key that needs to be set and...
22
by: BULYABA | last post by:
Another tragedy for me; i have a form called visit form whose record source is visit table; this contains some similar fields like the Registry; forexample school; so i would like to know if i...
6
by: JOSII | last post by:
Getting a string of boolean value into and out of the registry is no problem. Here's the problem: Although you can place an object into the registry and retreive it, I need to place an ArrayList...
0
by: Mogrin | last post by:
So I have this windows .net form app, and I have the following goals: -Needs to be 1 single file, the executable, in any directory the user decides to download it to. No installation folder, no...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.