If you were Registered and logged in, you could reply and use other advanced thread options
|
Posted by Luk on March 30, 2009, 9:51 am
Hello to all,
I'm far from being an expert of PHP, but I'm fighting with a light
procedure to remove trailing blank lines at the end of a file I've in
input from a user.
I'm using this code, but the lines containing a space and a \n at the
end, still remain :-(
$search = array(" ","\r\n","\r","\t","\n");
$replace = "";
$userfile = str_replace($search, $replace, $userfile);
$userfile=preg_replace("/^\n*$/","",$userfile);
//$userfile still has trailing blank lines at the end of file. Why?
many thanks!
Luk
|
|
Posted by Iván Sánchez on March 30, 2009, 10:05 am
Luk wrote:
> //$userfile still has trailing blank lines at the end of file. Why?
Because you're not using trim().
--
----------------------------------
Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-
Proudly running Debian Linux with 2.6.26-1-amd64 kernel, KDE 3.5.10, and PHP
5.2.6-3 generating this signature.
Uptime: 16:05:28 up 5 days, 19:06, 4 users, load average: 3.52, 2.81, 2.54
|
|
Posted by Luk on March 30, 2009, 3:20 pm
On 30 Mar, 16:05, Iv=E1n S=E1nchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.org> wrote:
> Luk wrote:
> > //$userfile still has trailing blank lines at the end of file. Why?
> Because you're not using trim().
> --
> ----------------------------------
> Iv=E1n S=E1nchez Ortega -ivan-algarroba-sanchezortega-punto-es-
> Proudly running Debian Linux with 2.6.26-1-amd64 kernel, KDE 3.5.10, and PHP
> 5.2.6-3 generating this signature.
> Uptime: 16:05:28 up 5 days, 19:06, =A04 users, =A0load average: 3.52, 2.81, 2.54
I used trim. But without results. Other hints?
thanks
Luk
|
|
Posted by Iván Sánchez on March 30, 2009, 3:56 pm
Luk wrote:
> I used trim. But without results. Other hints?
$userfile holds the *contents* and not the *name* of the file, right?
Right??
You are writing the trimmed stuff back to the file, right?
--
----------------------------------
Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-
Existen tres tipos de personas: las que saben contar y las que no.
|
|
Posted by Luk on March 31, 2009, 4:36 am
On 30 Mar, 21:56, Iv=E1n S=E1nchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.org> wrote:
> Luk wrote:
> > I used trim. But without results. Other hints?
> $userfile holds the *contents* and not the *name* of the file, right?
> Right??
> You are writing the trimmed stuff back to the file, right?
Yes, should be. This is the code used:
if (move_uploaded_file($_FILES['uploaded_file']['tmp_name'],
$userfile)) {
echo 'OK';
}
then after the checks about the spaces and other chars, there's the
foreach cicle that works:
$lines =3D file($userfile);
foreach ($lines as $line_num =3D> $line) {
//stuff
}
Luk
|
If you were Registered and logged in, you could reply and use other advanced thread options
Related Posts
Latest Posts
|