updating the registry

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ogo796
    New Member
    • Jan 2008
    • 44

    #1

    updating the registry

    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 ;
    [code=php]
    <?php




    $data =$_POST["name1"]." " .$_POST["name2"]."; ".$_POST["name3"]." \n";

    $q=$_POST["path"];


    $myArray = file($q."myfile .txt");



    $fp = fopen($q."Regis try.txt", "w");


    array_push($myA rray,$data);


    usort($myArray, "strnatcmp" );



    //Loop through the registry array

    foreach ($myArray as $value)

    {

    //Write the sorted contents to registry line-by-line

    fwrite($fp,$val ue);



    }



    // Close the registry file

    fclose($fp);



    ?>
    [/code]
    Last edited by Atli; Aug 1 '08, 08:09 PM. Reason: Added [code] tags
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    [PHP]<?php

    # GET DATA
    if(!(isset($_PO ST['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($_POS T['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($myF ile,$data);



    # GET REGISTRY FILE
    if(!$registryFi le = fopen($q."Regis try.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($reg istryFile,$line ))
    {
    die("Error: Unable to write to ");
    }
    }


    # CLOSE THE FILES
    fclose($registr yFile);
    fclose($myFile) ;


    # RESULT
    echo "Successful .";

    ?> [/PHP]

    Comment

    • ogo796
      New Member
      • Jan 2008
      • 44

      #3
      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;

      Comment

      Working...