Bug #2459: trim converts single newline into null

From: Date: Thu, 07 Oct 1999 01:03:13 +0000
Subject: Bug #2459: trim converts single newline into null
Groups: php.dev 
Request: Send a blank email to php-dev+get-11590@lists.php.net to get a copy of this message
From: alderete@be.com Operating system: FreeBSD PHP version: 3.0.12 PHP Bug Type: Misbehaving function Bug description: trim converts single newline into null While working on some form validation code, I came across what seems like a corner case for the trim function. I have two address fields on my form, and to validate them, I concatenate them together with a newline in between, and then trim the result. Then I check to see if this is the empty string. If both form fields are empty, the concatenation produces a single newline. Applying trim to that changes the variable to contain a single null [str (0)], instead of producing an empty string as expected. Put another way, the result of the below code produces a string where sizeof() == 1, instead of 0. Here's the sample code that triggers it for me: $ADDRESS_1 = ""; $ADDRESS_2 = ""; $ADDRESS = trim ($ADDRESS_1 . "\n" . $ADDRESS_2); if (ord ($ADDRESS) == 0) { print ("Newline converted to null!"); };

« previous php.dev (#11590) next »