note 98812 added to function.trim

From: Date: Fri, 09 Jul 2010 09:28:06 +0000
Subject: note 98812 added to function.trim
Groups: php.notes 
Request: Send a blank email to php-notes+get-170808@lists.php.net to get a copy of this message
[Editor: I botched my last note; please delete and use this one] Non-breaking spaces can be troublesome with trim (as per an earlier comment): // turn some HTML with non-breaking spaces into a "normal" string $myHTML = "&nbsp;abc"; $converted = strtr($myHTML, array_flip(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES))); // this WILL NOT work as expected // $converted will still appear as " abc" in view source // (but not in od -x) $converted = trim($converted); // &nbsp; are translated to 0xA0, so use: $converted = trim($converted, "\xA0"); // <- THIS DOES NOT WORK // EDITED>> // UTF encodes it as chr(0xC2).chr(0xA0) $converted = trim($converted,chr(0xC2).chr(0xA0)); // should work // PS: Thanks to John for saving my sanity! ---- Server IP: 69.147.83.197 Probable Submitter: 178.41.118.166 ---- Manual Page -- http://www.php.net/manual/en/function.trim.php Edit -- https://master.php.net/note/edit/98812 Del: integrated -- https://master.php.net/note/delete/98812/integrated Del: useless -- https://master.php.net/note/delete/98812/useless Del: bad code -- https://master.php.net/note/delete/98812/bad+code Del: spam -- https://master.php.net/note/delete/98812/spam Del: non-english -- https://master.php.net/note/delete/98812/non-english Del: in docs -- https://master.php.net/note/delete/98812/in+docs Del: other reasons-- https://master.php.net/note/delete/98812 Reject -- https://master.php.net/note/reject/98812 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#170808) next »