{"id":160,"date":"2005-08-03T01:50:59","date_gmt":"2005-08-03T00:50:59","guid":{"rendered":"http:\/\/www.malcolmhardie.com\/weblogs\/angus\/?p=160"},"modified":"2025-02-01T03:04:16","modified_gmt":"2025-02-01T03:04:16","slug":"php-trim-and-the-non-breaking-space","status":"publish","type":"post","link":"https:\/\/www.malcolmhardie.com\/weblogs\/angus\/2005\/08\/03\/php-trim-and-the-non-breaking-space\/","title":{"rendered":"PHP, trim and the non breaking space"},"content":{"rendered":"<p>An odd thing occurred today, I was trying to do <a href=\"http:\/\/uk.php.net\/trim\">trim($string) <\/a>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 <a href=\"http:\/\/www.barebones.com\/products\/textwrangler\/index.shtml\">TextWrangler<\/a>. Finally I tried <a href=\"http:\/\/uk.php.net\/substr\">substr($string,1) <\/a>and then I got the answer, the new string started <strong>nbsp; <\/strong>the string I was trimming had <strong>&amp;nbsp;<\/strong>, a non-breaking space at the beginning, which trim doesn&#8217;t remove. A quick switch to <a href=\"http:\/\/uk.php.net\/manual\/en\/function.str-replace.php\">str_replace<\/a> and now my string doesn&#8217;t have a space at the beginning. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,10],"tags":[],"class_list":["post-160","post","type-post","status-publish","format-standard","hentry","category-internet-stuff","category-macintosh"],"_links":{"self":[{"href":"https:\/\/www.malcolmhardie.com\/weblogs\/angus\/wp-json\/wp\/v2\/posts\/160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.malcolmhardie.com\/weblogs\/angus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.malcolmhardie.com\/weblogs\/angus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.malcolmhardie.com\/weblogs\/angus\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.malcolmhardie.com\/weblogs\/angus\/wp-json\/wp\/v2\/comments?post=160"}],"version-history":[{"count":1,"href":"https:\/\/www.malcolmhardie.com\/weblogs\/angus\/wp-json\/wp\/v2\/posts\/160\/revisions"}],"predecessor-version":[{"id":1525,"href":"https:\/\/www.malcolmhardie.com\/weblogs\/angus\/wp-json\/wp\/v2\/posts\/160\/revisions\/1525"}],"wp:attachment":[{"href":"https:\/\/www.malcolmhardie.com\/weblogs\/angus\/wp-json\/wp\/v2\/media?parent=160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.malcolmhardie.com\/weblogs\/angus\/wp-json\/wp\/v2\/categories?post=160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.malcolmhardie.com\/weblogs\/angus\/wp-json\/wp\/v2\/tags?post=160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}