|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[1999-10-07 09:17 UTC] andrei at cvs dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 14 18:00:02 2026 UTC |
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!"); };