Buying Small fix to a script 5$

Discussion in 'Programming' started by loghinandrei, May 21, 2010.

  1. #1
    Hello this is the script I have...
    <?php
    
    $d = file_get_contents('proxies.txt');
    
    $d = explode("\n", $d);
    echo count($d)."\n";
    $d = array_unique($d);
    echo count($d);
    
    $d = implode("\n",$d)."\n";
    file_put_contents('proxies.txt', $d);
    ?>
    Code (markup):
    I need it apart from removing the duplicate lines to delete the last blank line from proxies.txt ..
    That's it easy job for somebody understanding php.
     
    loghinandrei, May 21, 2010 IP
  2. kishore415

    kishore415 Well-Known Member

    Messages:
    1,462
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    160
    As Seller:
    100% - 0
    As Buyer:
    25.0% - 1
    #2
    try the below code...

    <?php
    
    $d = file_get_contents('proxies.txt');
    
    $d = explode("\n", $d);
    echo count($d)."\n";
    $d = array_unique($d);
    echo count($d);
    
    $d = implode("\n",$d);
    file_put_contents('proxies.txt', $d);
    ?>
    Code (markup):
     
    kishore415, May 21, 2010 IP
  3. loghinandrei

    loghinandrei Member

    Messages:
    223
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    35
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    Note the blank line at the end ....
    Your script doesn't work:)
     
    loghinandrei, May 21, 2010 IP
  4. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    As Seller:
    100% - 0
    As Buyer:
    100% - 1
    #4
    <?php

    $d = file_get_contents('proxies.txt');

    $d = explode("\n", $d);
    echo count($d)."\n";
    $d = array_unique($d);
    echo count($d);
    $d = implode("\n",$d);


    $newstring = '';
    foreach(file("proxies.txt") as $line)
    {
    if(trim($line) != '')
    {
    $newstring .= $line;
    }
    }


    file_put_contents('proxies.txt', $d);
    ?>

    check now

    regards

    Alex
     
    Last edited: May 21, 2010
    kmap, May 21, 2010 IP
  5. kishore415

    kishore415 Well-Known Member

    Messages:
    1,462
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    160
    As Seller:
    100% - 0
    As Buyer:
    25.0% - 1
    #5
    Try this...

    <?php
    
    $d = file_get_contents('proxies.txt');
    
    $d = explode("\n", $d);
    echo count($d)."\n";
    $d = array_unique($d);
    $d = array_filter($d);
    echo count($d);
    
    $d = implode("\n",$d);
    file_put_contents('proxies.txt', $d);
    ?>
    Code (markup):
     
    kishore415, May 21, 2010 IP
  6. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #6
    gapz101, May 21, 2010 IP
  7. loghinandrei

    loghinandrei Member

    Messages:
    223
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    35
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #7
    Everybody stop now please!
    Somebody that contacted my by pm sent me an working script so it will take the money I will post the script here for no fluffs etc

    <?php
    if(!function_exists('file_put_contents'))
    {
    	function file_put_contents($file, $contents)
    	{
    		$fh = fopen($file, 'w');
    		if($fh)
    		{
    			fwrite($fh, $contents);
    			fclose($fh);
    		}
    	}
    }
    
    /**
     * this is the main code
     */
    $c = file('proxies.txt');
    $n = array();
    foreach($c as $l)
    {
    	if(trim($l) == '') continue;
    	$l = str_replace(array("\r","\n"),array('',''), $l);
    	$n[md5($l)] = $l;
    }
    file_put_contents('proxies.txt', implode("\n", $n)); // --> change filename to original (proxies.txt)
    // --> end of main code :D
    
    echo 'Before:<br/> <textarea rows="10" cols="50">', file_get_contents('proxies.txt'), '</textarea><br/><br/>';
    echo 'After:<br/> <textarea rows="10" cols="50">', file_get_contents('proxies_new.txt'), '</textarea>';
    Code (markup):
     
    loghinandrei, May 21, 2010 IP
  8. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    As Seller:
    100% - 0
    As Buyer:
    100% - 1
    #8
    <?php

    $d = file_get_contents('proxies.txt');

    $d = explode("\n", $d);
    echo count($d)."\n";
    $d = array_unique($d);
    $count= count($d);
    $d = implode("\n",$d);
    file_put_contents('proxies.txt', $d);

    $newstring = '';
    foreach(file("proxies.txt") as $line)
    {
    if(trim($line) != "" )
    {
    if ($count==2)
    {
    $l = explode("\n", $line);
    $line=$l[0];
    }
    $newstring .= $line;
    echo $count;
    $count--;
    }
    }


    file_put_contents('proxies.txt', $newstring);
    ?>

    here it is

    Regards

    Alex
     
    kmap, May 21, 2010 IP
  9. loghinandrei

    loghinandrei Member

    Messages:
    223
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    35
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #9
    Thank you kmap for your time and others but as you see gapz101's already done it , and btw even with the last script of yours remains a blank line at the end...
    Thanks again gapz101
     
    loghinandrei, May 21, 2010 IP