PDA

View Full Version : Why aren't my whitespace being trimmed?


cyphix
11-06-2004, 04:34 PM
I just did up this little script to trim whitespace from the start & end of each line in a file plus some extra stuff but when I downloaded the new text file off my server & opened it, it still had the whitespace @ the start & end of the lines.

Any help?

Here is the code:


<?php

$time = time();

$file = file('database.txt');

$newfile = "**************";

foreach ($file as $val) {

trim($val);

if (strpos($val, "(DC)") == false) {

$insert = fopen($newfile, "a");

fputs($insert, $val);

fclose($insert);

}

}

$newtime = time();

$ftime = $newtime - $time;

echo "<b>Done in $ftime seconds!</b>";

?>

marek_mar
11-06-2004, 05:26 PM
Change

trim($val);

to

$val = trim($val);

cyphix
11-06-2004, 05:42 PM
Easy one.. thanks for that! :D