 <p>It's not safe to do it your way, since there may also be \r or \n in a SQL statement (e.g. a long TEXT with many lines).</p> <p>If you're sure there aren't case like that, I'd suggest you to use <a href="http://www.php.net/trim" rel="nofollow">trim()</a> instead of <a href="http://www.php.net/str_replace" rel="nofollow">str_replace()</a>. It'll remove all spaces and EOL at the end of each lines.</p> <pre><code>&lt;?php $tmp = trim($line); ?&gt; </code></pre> <p>You may also specify to ONLY REMOVE EOL (both "\r\n" and "\n") like this:</p> <pre><code>&lt;?php $tmp = trim($line, "\r\n"); ?&gt; </code></pre>