A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: removing a blank line in txt file with php

  1. #1
    Senior Member Vincent26381's Avatar
    Join Date
    Feb 2003
    Location
    The Netherlands
    Posts
    833

    removing a blank line in txt file with php

    Hi,

    I made this super simple (learning) php script to subscribe to an e-mail list, send the mails with a webbased textfield and that works all ok. The problem is unsubscribing.

    In the mail is a link like this: http://wwww.somhost.com/unsubscribe....urmail@isp.com

    I made a form where the initial value is that email, when they press the submit button it posts it to this script:
    (Ihave 1 e-mail per line)

    PHP Code:
    $T1 $_POST['T1']; 

    $splitmails file("themails.dat");
    $tn 0;
    for (
    $i 0$i count($splitmails); $i++) { 

    $deleteadres $splitmails[$tn];
    $tn++;

    $deleteadres str_replace("$T1"""$deleteadres);

    $fp .= $deleteadres;
    }

    $a fopen("themails.dat""w"); 
    fputs($a"$fp");
    fclose($a);
    ?> 
    This leaves a blank line where the unsubscribed e-mail was. Is there any way to remove that blank line too?

    Thanks
    Vincent
    SWIS BV

    Last edited by Markp.com on 07-23-2003 at 02:25 AM

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    the possible problem with your script:
    if a@abc.com and ua@abc.com are both subscribed, it will even leave a plain u

    Consider this snippet
    Code:
    $newlist = array();
    for($n = 0 ; $n < count($splitmails ; $n++)
      if(!eregi("^$T1", $splitmails[$n]))
         $newlist[] = $splitmails[$n];
    Of course you want to save the $newlist this time.
    If there is ever a chance that two people unsubscribe at the same time, you would have to replace your file handling

    Musicman

  3. #3
    Senior Member Vincent26381's Avatar
    Join Date
    Feb 2003
    Location
    The Netherlands
    Posts
    833
    Never thought of that, but it could well be possible indeed.
    To get thing clear, eregi checks if it is that precise email and takes out the email that is equal to $T1 ?

    Then i would write that array to the textfile again like this(?)

    PHP Code:
    <?
    $T1 = $_POST['T1']; 

    $splitmails = file("themails.dat");

    $newlist = array();

    $tn = 0;
    for($n = 0 ; $n < count($splitmails ; $n++){
      if(!eregi("^$T1", $splitmails[$n]))
         $newlist[] = $splitmails[$n];

    // I think this adds it to $fp
    $fp .= $newlist[$tn] . "\n";
    // add a new line?
    $tn++
    }

    $a = fopen("themails.dat", "w"); 
    fputs($a, "$fp");
    fclose($a);
    ?>
    If two people run this script the same time, would that mean it could mess up 'themails.dat'? I was hoping PHP would handle that for me (processing one after another).

    Is there a way to script around this (without using a db)?

    Thanks for your suggestions and help
    Vincent
    SWIS BV

    Last edited by Markp.com on 07-23-2003 at 02:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center