SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a text file of email addresses. The lines look like this:

    ivymoe@mindspring.com Email from plus one online Sun 12/31/00 6:22 PM

    I would like to get rid of the part in bold, but I don't want to go through all 600 lines by hand. I know that it can be done with regex and indeed I have done lesser thing than this myself. I just can't figure out how to get this one set up.

    Anyone have a solution?
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    which part is in bold? I would do it like this

    $file = file("yourtextfile");
    for($i=0;$i<count($file);$i++) {
    $data[] = str_replace("texttoreplace", "", $file[$i]);
    }
    $fp = fopen("sametextfile", "w");
    for($i=0;$i<count($data);$i++) {
    fputs($fp, $data[$i]."\n");
    }
    fclose($fp);
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ivymoe@mindspring.com Email from plus one online Sun 12/31/00 6:22 PM
    Sorry bout that folks...forgot about the bold bit. The key is that the date and time at the end changes...it is however, always in the same format.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $file = file("yourtextfile");
    $fp = fopen("sametextfile", "w");

    for($i=0;$i<count($file);$i++) {
    fputs($fp, substr($file[$i], 0, strpos($file[$i], " "))."\n");
    }
    fclose($fp);
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured it out... I had to do it in like 4 steps, but I got it after all...

    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you try it my way I am positive it is ten times faster than taking ten steps.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am sure your way would be faster...especially if I was doing it more than once, but for this one time I didn't mind doing it the hard way. It still only took me about 3 minutes...so no big deal.

    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  8. #8
    Non-Member
    Join Date
    Apr 2000
    Location
    Waco, Texas.
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know you have already done it, but I decided to write some code anyhow.
    Code:
    <?
    $file = "C:\Windows\Desktop\untitled.txt";
    $content = implode('',file($file));
    $content = preg_replace("/([^\s]*)[^\n]*/","\\1",$content);
    $out = fopen($file, "w");
    fputs($out,$content);
    fclose($out);
    
    print $content;
    ?>
    Freddy, since the date is on the line, I am thinking that each line contains different dates, so having:
    str_replace("Email from plus one online Sun 12/31/00 6:22 PM","", $file[$i]);
    would only affect one line most likely. Not sure is str_replace() would be the best function to use than, because I don't think it can handle complex string patterns? (I could always be wrong about that though)


  9. #9
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guess you didn't see my second post?? Which would definetly be faster than imploding each line and using preg.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

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