Trim only tab and newline characters from $str
<? $str = " string \t \n"; $str = trim ($str, "\t\n"); echo( $str ); echo(strlen($str)); ?>