Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: Deleting a line of a TXT file.

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

    Default Deleting a line of a TXT file.

    I want this script to instead of saying you're a guest, into deleting a line in a TXT file.

    Is this possible?

    Below is the script I'm using.

    if(stripos(file_get_contents('http://www.othersite.com/page.html'), '<script')!== false)
    echo('YES');
    else
    echo('NO')



    also is it possible to "search" for a tag or something in the text code and delete it?

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

    Default

    What does the text file look like? This is very possible but we need a little more information.

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

    Default

    something like

    <a href="http://www.google.com">
    Google Search Engine </a>
    <BR>
    Description: A really famous search engine. If you dont know what this is... well.. eh..... um.... crawl under a rock.

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

    Default

    Is that all on one line? If not what line do you want deleted?

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

    Default

    yeah, if its possible to be deleted...

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

    Default

    I'm still not quite clear on what the file looks like. Could you provide an example with more than one? Also please make use of the code tags.

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

    Default

    i just want to delete, say 4-5 lines of HTML code.
    such as:
    Code:
    <B>code</B>here....<BR>random html code.

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

    Default

    What distinguishes the lines you want to keep from the lines you want removed.

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

    Default

    erm.. can u show me some code of how to do it, and ill figure a way to do that.

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

    Default

    Ok,Here is a quick 'n dirty example.
    list.txt looks like this
    Code:
    http://www.dynamicdrive.com
    http://www.digg.com
    http://www.yahoo.com
    http://www.google.com
    http://www.ebay.com
    and index.php looks like this
    PHP Code:
    <html>
        <head>
        </head>
        <body>
            <ul>
        <?php
        
    if(!empty($_GET['line'])){
            
    $file file('list.txt');
            
    ob_start();
            for(
    $i=0;$i count($file);$i++){
                if(
    rtrim($file[$i]) != $_GET['line']){
                    echo 
    $file[$i];
                }
            }
            
    $write ob_get_contents();
            
    ob_end_clean();
            
    $handle fopen('list.txt','w');
            
    fwrite($handle,$write);
            
    fclose($handle);
        }
        
    $file file('list.txt');
        for(
    $i=0;$i<count($file);$i++){
            echo 
    '<li><a href="index.php?line='.urlencode(rtrim($file[$i])).'">Delete '.rtrim($file[$i]).'</a></li>'."\n";
        }
        
    ?>
            </ul>
        </body>
    </html>
    They both need to be in the same directory. Go ahead and run to see what it does

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
  •