Deprecated: Assigning the return value of new by reference is deprecated in /home/onepixel/public_html/wp-settings.php on line 472

Deprecated: Assigning the return value of new by reference is deprecated in /home/onepixel/public_html/wp-settings.php on line 487

Deprecated: Assigning the return value of new by reference is deprecated in /home/onepixel/public_html/wp-settings.php on line 494

Deprecated: Assigning the return value of new by reference is deprecated in /home/onepixel/public_html/wp-settings.php on line 530

Deprecated: Assigning the return value of new by reference is deprecated in /home/onepixel/public_html/wp-includes/cache.php on line 103

Deprecated: Assigning the return value of new by reference is deprecated in /home/onepixel/public_html/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /home/onepixel/public_html/wp-includes/theme.php on line 623

Deprecated: Assigning the return value of new by reference is deprecated in /home/onepixel/public_html/wp-content/plugins/paged-comments/paged-comments/paged-comments.php on line 159

Deprecated: Assigning the return value of new by reference is deprecated in /home/onepixel/public_html/wp-content/plugins/paged-comments/paged-comments/paged-comments.php on line 380

Deprecated: Assigning the return value of new by reference is deprecated in /home/onepixel/public_html/wp-content/plugins/paged-comments/paged-comments/paged-comments.php on line 382

Deprecated: Assigning the return value of new by reference is deprecated in /home/onepixel/public_html/wp-content/plugins/paged-comments/paged-comments/paged-comments.php on line 386

Deprecated: Assigning the return value of new by reference is deprecated in /home/onepixel/public_html/wp-content/plugins/paged-comments/paged-comments/paged-comments.php on line 481
1 Pixel Out » Blog Archive » trim() treachery

ColdFusion, WordPress, Flash & other web things


trim() treachery

trim() is probably the CF function I have used the most throughout my career. Today, this trusted and straightforward function behaved in the most unexpected way: it didn’t trim the string!

Now, the string I was attempting to trim was passed in from a textarea and had been pasted in from a spreadsheet cell and… IT DEFINITELY HAD A TRAILING SPACE! And this is the weirdest bit: when I ran the code in Firefox, the string ended up trimmed but in IE, the string still had the trailing space… ??!!!?

I even tried a regular expression (REReplace( string, "[[:space:]]+”, “”, “ALL” )) to remove all spaces but that didn’t remove the trailing space either.

I eventually found out that the problem was due to the trailing space being a non-breakable space (ascii 160). This special breed of white space must be immune to trims and excluded from the :space: family, which I suppose actually makes sense (“non-breakable” kind of means “non-removable”).

The fact that the space had been removed when using Firefox must mean that Mozilla browsers send non-breakable spaces as regular spaces.

Comments are closed.