PHP, trim and the non breaking space

An odd thing occurred today, I was trying to do trim($string) on a string in php, but I kept getting strings back that appeared to have a space at the beginning, the exact thing that trim is supposed to remove. I carefully checked and the space was definitely found when I copied the result out to TextWrangler. Finally I tried substr($string,1) and then I got the answer, the new string started nbsp; the string I was trimming had  , a non-breaking space at the beginning, which trim doesn’t remove. A quick switch to str_replace and now my string doesn’t have a space at the beginning. :-)

Leave a Reply