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.
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):
<?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
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):
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):
<?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
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