php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31301 trim() does not trim single whitespace variables
Submitted: 2004-12-26 07:36 UTC Modified: 2004-12-26 20:36 UTC
From: aitrus at tresgeek dot net Assigned:
Status: Not a bug Package: Strings related
PHP Version: 4.3.10 OS: Linux
Private report: No CVE-ID: None
 [2004-12-26 07:36 UTC] aitrus at tresgeek dot net
Description:
------------
When passed a string variable with a single space as its contents, trim() returns a variable with a single space as its contents.

Reproduce code:
---------------
$foo = " ";

$foo = trim( $foo );

echo "x{$foo}x";

--

output is: 'x x'

Expected result:
----------------
trim() should return a empty string (or false).


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-26 07:44 UTC] aitrus at tresgeek dot net
updated OS
 [2004-12-26 11:34 UTC] derick@php.net
Works fine here:
derick@kossu:~$ cat bug31301.php
<?php
$foo = " ";

$foo = trim( $foo );

echo "x{$foo}x";
?>

derick@kossu:~$ php-4.3dev bug31301.php
xx
 [2004-12-26 18:34 UTC] aitrus at tresgeek dot net
I apologize, my example was too simple and did not reproduce the problem:

$foo = "&nbsp;";

$foo = html_entity_decode( $foo, ENT_QUOTES );
$foo = trim( $foo );

echo "x{$foo}x";

output is:  'x x'
 [2004-12-26 20:28 UTC] derick@php.net
Still not a bug :)
&nbsp; gets converted not to a space (ascii 32) but to a non breaking space, which matches to ascii 160. And that character is not always a non breaking space in every character set so trim() should not trim it by default.
 [2004-12-26 20:36 UTC] aitrus at tresgeek dot net
grr!

thanks for your time.  =)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 11:01:30 2024 UTC