On Fri, 4 Sep 2009 14:58:55 +0200, ralph_def...@yahoo.de ("Ralph Deffke") wrote:

>Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap.
>using PHP_EOL would be great.

Here is a function which works for files pasted from browser screens:

function clean_up($dirty_file)
        {
        $contents = file_get_contents ($dirty_file);
        if ($contents)
                {
                $c_array = explode ("\n", $contents);
                $n = count($c_array);
                $i = 0; $j = 0; while ($i < $n)
                        {
                        $line = trim($c_array[$i]);
                        if ($line != '')
                                {
                                $d_array[$j++] = $c_array[$i];
                                }
                        ++$i;
                        }
                $clean = implode ("\n",$d_array);
                $data_file = file_put_contents($data_file, $clean);
                }
        }               

The virtue of this is you don't have to know, or care, what characters are on 
the blank
lines.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to