Mubashar Abbas
Mubashar Abbas

Reputation: 5663

PHP trim() not trimming space

I have run into a strange problem. I am trying to trim a string using php trim(), but it is not working.

Here is my code

echo $deal->{self::DEAL_BUSINESS};
echo '<br>';
echo trim($deal->{self::DEAL_BUSINESS});
echo '<br>';

And here is the output

 Alkaram Studio
 Alkaram Studio

If it is not clear from the output. There is a space in the beginning of both untrimmed and the trimmed string.

In the view source I got this.

&nbsp;Alkaram Studio

Upvotes: 5

Views: 5394

Answers (1)

callback
callback

Reputation: 4122

Try the following:

echo trim($deal->{self::DEAL_BUSINESS}, "\xC2\xA0\n");

Or

$text = preg_replace('~\x{00a0}~siu','',$deal->{self::DEAL_BUSINESS});
echo $text;

Upvotes: 10

Related Questions