GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Att.: scriptfreaks - Removing empty lines from textfile w/php (https://gfy.com/showthread.php?t=608094)

Naughty 05-10-2006 06:50 AM

Att.: scriptfreaks - Removing empty lines from textfile w/php
 
Hi,

We have a script that is adding new lines for no apparent reason at this time. I want to get rid of the empty lines and re-order the text file every time somebody ads her/his name.

The file is pretty simple, just lines, like this:
line1
...
...
line2
...
line1001
...

I want to loose the ... lines and have it all nicely formatted, like this
line1
line2
line1001


I use this script to add lines:
PHP Code:

        $FileName $path."/lists/names.php";
        
$list file($FileName);
        
$newitem $_POST["name"]."|^|".$_POST["enterpass"]."|^|".$_POST["enteremail"]."|^|";
        
$FilePointer fopen($FileName"a+");
        
fwrite($FilePointer"\n".$newitem);
        
fclose($FilePointer); 

Who knows how I can change that little piece of code and make it as wanted?

Thanks,
Paul

Naughty 05-10-2006 09:04 AM

Thanks :p

rowan 05-10-2006 09:17 AM

Try putting the \n at the end rather than at the start.

fwrite($FilePointer, "$newitem\n");

or

fputs($FilePointer, "$newitem\n");

psili 05-10-2006 09:37 AM

just a guess, after you run your insert, rebuild the file?

$file = file_get_contents($FileName);
$file = preg_replace("\n\n",$file);

fwrite($FilePointer,$file);

---
eh, nix that. probably an ugly way to do it.
just get the file fixed and insert correct new lines like rowan said.

SmokeyTheBear 05-10-2006 09:45 AM

put this as line #4
$newitem = trim($newitem);

im new at this so i could be wrong

Naughty 05-10-2006 10:39 AM

I did notice it just doubles the amoiunt of rows each time I update, add or edit a line from the file. I'm sure it has to do with /n, but I am still fucking around with it.

I'll try some of your options as well.

Naughty 05-10-2006 02:08 PM

None of the above worked, any other takers?

MickeyG 05-10-2006 02:15 PM

get rid of the \n when your appending to the file it already goes to the end of the file. The only time you need \n is if your appending multiple lines

Naughty 05-10-2006 02:21 PM

Quote:

Originally Posted by MickeyG
get rid of the \n when your appending to the file it already goes to the end of the file. The only time you need \n is if your appending multiple lines


If I do that, this

line2
line3
...


becomes:
line2line3
...


Using this code:
PHP Code:

        $FileName $path."/lists/names.php";
        
$list file($FileName);
        
$list[$line] = $_POST["name"]."|^|".$_POST["newpass1"]."|^|".$email."|^|";
        
$FileName $path."/lists/newnames.php";
        
$FilePointer fopen($FileName"w+");
        for (
$x=0;$x<=$numnames;$x++){
            
fwrite($FilePointer,$list[$x]);//."\n"
        
}
        
fclose ($FilePointer);
        
unlink($path."/lists/names.php");
        
rename($path."/lists/newnames.php",$path."/lists/names.php"); 


Naughty 05-10-2006 02:38 PM

This works:

PHP Code:

$FileName $path."/lists/names.php"
        
$list file($FileName); 
        
$listhahaha91;$linehahaha93; = $_POSThahaha91;"name"hahaha93;."|^|".$_POSThahaha91;"newpass1"hahaha93;."|^|".$email."|^|\n"
        
$FileName $path."/lists/newnames.php"
        
$FilePointer fopen($FileName"w+"); 
        for (
$x=0;$x<=$numnames;$x++){ 
            
fwrite($FilePointer,$listhahaha91;$xhahaha93;);
        } 
        
fclose ($FilePointer); 
        
unlink($path."/lists/names.php"); 
        
rename($path."/lists/newnames.php",$path."/lists/names.php"); 



All times are GMT -7. The time now is 01:07 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123