Hello, i'm really new to PHP, so i'll try to explain my problem the best i can..

Im creating a news board in flash, its a pretty typical setup, the user has his/hers admin page, this is where they enter a new post, flash submits the post to PHP and PHP writes the new post into a .txt file for the main flash page to pick up.

this is where the problem is, The txt file needs to retain news= at the very beginning of the .txt file after every post,

for example, the .txt file would read;

news= <p>12/12/07, this is a post about something<br /></p>
<p>13/12/07, and another<br /></p>
<p>14/12/07, and another<br /></p>

this is my current PHP code which adds the post, but doesn't write news= at the begining of the .txt file like i need it to.

<?php
    $Submit     = $_POST["Submit"];
    $post         = $_POST["new_news"];
    $post        = ereg_replace('[^A-Za-z 0-9,./?><";:\~!\'\"\/@#[](){}]', "", $post);


if ($Submit == "Yes") {
    $filename     = "../news.txt";
    $fp         = fopen( $filename,"r+");
    $old_data     = fread($fp,  80000);

    fclose( $fp ); 



    $date        = (date ("(g:i A) l - d F Y"));
    $input         = "<p align=\"left\">$date<br>$post<br></p>";
    $new         = "$input$old_data";

    $fp         = fopen( $filename,"w");
    if(!$fp) die("&error    =Failed to write!");
    fwrite($fp, $new, 800000);
    fclose( $fp );
}   
?>

Could someone PLLEEEAASSEEE help me with this, i've been stuck on it for 2 days!

if you need me to explain it further, then just ask...

    ok, i thought i had it with this

    <?php
    $Submit = $POST["Submit"];
    $post = $
    POST["new_news"];
    $post = ereg_replace('[A-Za-z 0-9,./?><";:\~!\'\"\/@#{}]', "", $post);

    if ($Submit == "Yes") {
        $filename     = "../news.txt";
        $fp         = fopen( $filename,"r+");
        $old_data     = fread($fp,  80000);
    fclose( $fp ); 
    
        [B]$news = "news=";[/B]
        $date        = (date ("(g:i A) l - d F Y"));
        $input         = "<p align=\"left\">$date<br>$post<br></p>";
        $new         = "$input$old_data ";
    
        $fp         = fopen( $filename,"w");
        if(!$fp) die("&error    =Failed to write!");
        fwrite($fp, $news,[B]$new[/B], 800000);
        fclose( $fp );
    }   
    ?>

    now it doesnt write to the .txt file at all :eek:

      You might want to use php code tags. The problem probably lies in the use of both $news and $new.

        i tryed a completely different name, but still no luck. could str_replace be used where to fix my problem?

        <?php
        $Submit = $_POST["Submit"];
        $post = $_POST["new_news"];
        $post = ereg_replace('[^A-Za-z 0-9,./?><";:\~!\'\"\/@#[](){}]', "", $post);
        
        
        if ($Submit == "Yes") {
        $filename = "../news.txt";
        $fp = fopen( $filename,"r+");
        $old_data = fread($fp, 80000);
        fclose( $fp );
        
        $flash = "news=";
        $date = (date ("(g:i A) l - d F Y"));
        $input = "<p align=\"left\">$date<br>$post<br></p>";
        $new = "$input$old_data ";
        
        $fp = fopen( $filename,"w");
        if(!$fp) die("&error =Failed to write!");
        fwrite($fp, $flash ,$new, 800000);
        fclose( $fp );
        }
        ?>

          $input = "news=<p align=\"left\">$date<br>$post<br></p>";

            thanks halfaBee
            i tryed that, but unfortunity it wrote news= at the beginning of each and every post . not what i was wanting.

            but i've finally found the solution anyway. i created another file, reader.PHP and passed $old_data from add.PHP to reader.PHP and echoed it like so...

             <?php
            $filename	= "news.txt";
            $fp = fopen( $filename,"r"); 
            $OldData = fread($fp, 80000);
            fclose( $fp );
            echo "news=$OldData"
            ?>

            🙂

              Sorry didn't understand what you wanted.

              $input = "news=<p align=\"left\">$date<br>$post<br></p>";
              $old_data = str_replace( 'news=' , '' , $old_data );
              $new = "$input.$old_data ";

                Write a Reply...