function UberTrim($s) {
$s = preg_replace('/\xA0/u', ' ', $s);
$s = trim($s);
return $s;
}
The UTF-8 character encoding for non-breaking space, Unicode (U + 00A0), is a 2-byte sequence C2 A0 . I tried using the second parametertrim() , but that did not help. Usage example:
assert("abc" === UberTrim(" \r\n \xc2\xa0 abc \t \xc2\xa0 "));
MySQL TRIM(text_field), UTF, @RudolfRein:
TRIM(REPLACE(text_field, '\xc2\xa0', ' '))
UTF-8:
( )
, PHP
UTF-8 . .
, MySQL UTF-8 ( ),
$pdo = new PDO('mysql:host=...;dbname=...;charset=utf8',$userid,$password);
$pdo->exec("SET CHARACTER SET utf8");
, HTTP UTF-8, . Apache:
AddDefaultCharset UTF-8
, UTF-8.
header('Content-Type: text/html; charset=utf-8');
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />