Jens Törnell
Jens Törnell

Reputation: 24748

Trim does not strip spaces

I've read plenty of answers but never found a solution.

Why doesn't this work with trim?

$test = trim('Whatever this     is');
echo $test;

This work:

$test= preg_replace('/\s+/', ' ', 'Whatever this     is');
echo $test;

Expected:

Whatever this is

Why doesn't the first one work, when the second one does? No strange characters as I write them directly in the PHP code.

Please don't close this one too quickly

Upvotes: 0

Views: 76

Answers (1)

Jenz
Jenz

Reputation: 8369

trim strips spaces only from beginning and end of a string. Please refer this link.

Upvotes: 6

Related Questions