 <p>Your string is equal to <code>\r\n\r\n\t\r\ndata\r\n\t</code> which is <code>CR LF CR LF TAB CR LF "data" CR LF TAB</code>. You're only trimming <code>LF</code> (<code>\n</code>) in your <code>trim()</code> call, which is why you don't trim <code>CR</code> (<code>\r</code>) and <code>TAB</code> (<code>\t</code>) also present in your string. </p> <p>Try removing the second parameter (which specifies what characters should be trimmed), it will take care all of the whitespace characters.</p> <p>As of <a href="http://www.php.net/manual/en/function.trim.php" rel="nofollow">Docs</a>:</p> <blockquote> <p>This function returns a string with whitespace stripped from the beginning and end of str. <strong>Without the second parameter, trim() will strip these characters:</strong></p> </blockquote> <pre><code>" " (ASCII 32 (0x20)), an ordinary space. "\t" (ASCII 9 (0x09)), a tab. "\n" (ASCII 10 (0x0A)), a new line (line feed). "\r" (ASCII 13 (0x0D)), a carriage return. "\0" (ASCII 0 (0x00)), the NUL-byte. "\x0B" (ASCII 11 (0x0B)), a vertical tab. </code></pre>