...

View Full Version : Remove empty lines



awsomejoe23
03-02-2008, 06:31 AM
I have a .txt file that has something like this

1
<a href="/projects/emule/">eMule</a>
391,631,805


2
<a href="/projects/azureus/">Azureus</a>
162,516,119


3
<a href="/projects/aresgalaxy/">Ares Galaxy</a>
144,396,278


4
<a href="/projects/bittorrent/">BitTorrent</a>
51,850,559

I need all the empty line deleted.
I've tried the following


function removeEmptyLines($string)
{
return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $string);
}
_____________________________________
$content = eregi_replace("\"","'",$content);
$content = eregi_replace("\n","",$content);
$content = eregi_replace("\r","",$content);



Thank you for your time and effort,

Joe

_Aerospace_Eng_
03-02-2008, 07:19 AM
So what kind of output are you expecting?

digitalfiz
03-02-2008, 10:32 AM
You could load the file with file() and loop through the lines like so:


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

I'm not very good with regexp so this would be the way i would do it. May not be the l33t way or the most efficient way but it works :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum