angelcool.net
angelcool.net

Reputation: 2546

Why is PHP's trim() not removing trailing blank space?

The following line is not echoing the expected result:

echo "|".trim(" Laura Suárez Samper ")."|";

The above outpus:

|Laura Suárez Samper |

If I urlencode() the blank space I get:

%e2%80%83

Any ideas ?

Thanks

Upvotes: 0

Views: 81

Answers (1)

angelcool.net
angelcool.net

Reputation: 2546

I went ahead and used the following unicode-safe trim:

function unicodeSafeTrim($str)
{
    // unicode-safe trim, removes other and sepatator categories.
    return preg_replace("/^[\pZ\pC]+|[\pZ\pC]+$/u", "", $str);
}

It worked like a charm.

Upvotes: 1

Related Questions