Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 23

Thread: Deleting a line of a TXT file.

  1. #11
    Join Date
    Aug 2006
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks, but can u help me 'automatically' do it and somehow use preg_replace or str_replace?

  2. #12
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    'automatically' based on what?

  3. #13
    Join Date
    Aug 2006
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    acutrally..

    when a website is visited, then it will delete text.

  4. #14
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Ok, I see the connection now. That is code I gave you before right? Not sure how to test this so...it is untested
    PHP Code:
    <html>
        <head>
        </head>
        <body>
        <?php
            $affiliate 
    'somesite.com'//Don't add anything that isn't ALWAYS in the URL
            
    if(strpos(strtolower($_SERVER['HTTP_REFERER']),$affiliate) !== false){
                
    $add $affiliate;
            }
            else{
                
    $del $affiliate;
            }
        if(!empty(
    $del)){
            
    $file file('list.txt');
            
    ob_start();
            for(
    $i=0;$i count($file);$i++){
                if(
    rtrim($file[$i]) != $del){
                    echo 
    $file[$i];
                }
            }
            
    $write ob_get_contents();
            
    ob_end_clean();
            
    $handle fopen('list.txt','w');
            
    fwrite($handle,$write);
            
    fclose($handle);
        }
        else if(!empty(
    $add)){
            
    $handle fopen('list.txt','a');
            
    fwrite($handle,$add."\n");
            
    fclose($handle);
        }
        
    ?>
        </body>
    </html>

  5. #15
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Ok, yeah list.txt needs to look like this
    Code:
    dynamicdrive.com
    digg.com
    yahoo.com
    google.com
    ebay.com

  6. #16
    Join Date
    Aug 2006
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    what will this delete? Only the url, right?
    i want it to delete some text after the url. hope im not bothering you with all my questions

  7. #17
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Quote Originally Posted by me
    I'm still not quite clear on what the file looks like. Could you provide an example with more than one
    Quote Originally Posted by cursed
    erm.. can u show me some code of how to do it, and ill figure a way to do that.
    So, I repeat. what does the file look like exactly?

  8. #18
    Join Date
    Aug 2006
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Code:
    <a href="http://www.urlhere.com">Test</a> <BR> Description: A test website about blah.

  9. #19
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    PHP Code:
    <?php
    function deleteline($del,$filename){
        
    $file file($filename);
        
    ob_start();
        for(
    $i=0;$i count($file);$i++){
            if(
    strpos($file[$i],$del) === FALSE){
                echo 
    $file[$i];
            }
        }
        
    $write ob_get_contents();
        
    ob_end_clean();
        
    $handle fopen('list.txt','w');
        
    fwrite($handle,$write);
        
    fclose($handle);
    }
    //Pass in the search term, then the filename
    deleteline('google','list.txt');
    ?>
    Here I've written a function to do what you want. I'll leave it up to you to determine how to use it.

  10. #20
    Join Date
    Aug 2006
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks, oh grand PHP coder.

    this will delete every line that has the word google in it, right?

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
  •