Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP trim() not trimming space

Tags:

php

trim

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
like image 467
Mubashar Abbas Avatar asked Apr 22 '16 11:04

Mubashar Abbas


1 Answers

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;
like image 197
callback Avatar answered Sep 27 '22 22:09

callback