Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 05-10-2006, 06:50 AM   #1
Naughty
Confirmed User
 
Industry Role:
Join Date: Jul 2001
Location: Utopia
Posts: 6,484
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
__________________
seks.ai for sale - ping me
Naughty is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-10-2006, 09:04 AM   #2
Naughty
Confirmed User
 
Industry Role:
Join Date: Jul 2001
Location: Utopia
Posts: 6,484
Thanks :p
__________________
seks.ai for sale - ping me
Naughty is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-10-2006, 09:17 AM   #3
rowan
Too lazy to set a custom title
 
Join Date: Mar 2002
Location: Australia
Posts: 17,393
Try putting the \n at the end rather than at the start.

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

or

fputs($FilePointer, "$newitem\n");
rowan is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-10-2006, 09:37 AM   #4
psili
Confirmed User
 
Join Date: Apr 2003
Location: Loveland, CO
Posts: 5,526
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.
__________________
Your post count means nothing.
psili is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-10-2006, 09:45 AM   #5
SmokeyTheBear
►SouthOfHeaven
 
SmokeyTheBear's Avatar
 
Join Date: Jun 2004
Location: PlanetEarth MyBoardRank: GerbilMaster My-Penis-Size: extralarge MyWeapon: Computer
Posts: 28,609
put this as line #4
$newitem = trim($newitem);

im new at this so i could be wrong
__________________
hatisblack at yahoo.com
SmokeyTheBear is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-10-2006, 10:39 AM   #6
Naughty
Confirmed User
 
Industry Role:
Join Date: Jul 2001
Location: Utopia
Posts: 6,484
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.
__________________
seks.ai for sale - ping me
Naughty is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-10-2006, 02:08 PM   #7
Naughty
Confirmed User
 
Industry Role:
Join Date: Jul 2001
Location: Utopia
Posts: 6,484
None of the above worked, any other takers?
__________________
seks.ai for sale - ping me
Naughty is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-10-2006, 02:15 PM   #8
MickeyG
Confirmed User
 
Join Date: May 2004
Location: South Florida
Posts: 4,134
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
MickeyG is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-10-2006, 02:21 PM   #9
Naughty
Confirmed User
 
Industry Role:
Join Date: Jul 2001
Location: Utopia
Posts: 6,484
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"); 
__________________
seks.ai for sale - ping me
Naughty is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-10-2006, 02:38 PM   #10
Naughty
Confirmed User
 
Industry Role:
Join Date: Jul 2001
Location: Utopia
Posts: 6,484
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"); 
__________________
seks.ai for sale - ping me
Naughty is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.