[PHP-DEV] Bug #2459: trim converts single newline into null From: alderete <email protected>
Date: 10/06/99

From: alderete <email protected>
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!");
};

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>