Trim   with PHP Trim   with PHP php php

Trim   with PHP


Found this at php.net, works great:

$myHTML = " abc"; $converted = strtr($myHTML, array_flip(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES))); trim($converted, chr(0xC2).chr(0xA0));

Source: http://php.net/manual/en/function.trim.php#98812


$str = "1 $nbsp;     2     3   4";$new_str = str_replace(" ", '', $str);


A more inclusive answer for those who want to just do a trim:

$str = trim($str, " \t\n\r\0\x0B\xC2\xA0");

Same trim handling   html entities:

$str = trim(html_entity_decode($str), " \t\n\r\0\x0B\xC2\xA0");

This html_entity_decode and trim interaction is outlined in the PHP docs here:http://php.net/manual/en/function.html-entity-decode.php#refsect1-function.html-entity-decode-notes