Manixat Posted April 12, 2013 Share Posted April 12, 2013 (edited) Hello freaks, I have a textarea for writing comments where users can input many new lines and I'm trying to clean those lines but nothing seems to be working. I went all over all google results and tried every example both with preg replace and str replace and nothing seems to work. What I'm doing is first escaping the comment string then trim(preg_replace()). Am I doing the order wrong or idk what might be wrong. I tried like at least 20 syntaxes and none worked, and that's when I write a comment like "asd asd" if I write a comment like "asd " then the new lines are gone in the display of the comment but are still saved in the database which I do not want ... Edited April 12, 2013 by Manixat Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted April 12, 2013 Share Posted April 12, 2013 Show us some example input, what you expect to be returned and what is actually returned as well as the code you currently have. Quote Link to comment Share on other sites More sharing options...
Solution Manixat Posted April 12, 2013 Author Solution Share Posted April 12, 2013 Ofcourse by the laws of the universe, after I posted this thread I tried to do the replace before I escape the string and it worked. Apparantly when a string is escaped \n is not \n anymore. Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted April 12, 2013 Share Posted April 12, 2013 There are 3 different types of new lines, all depending on the system the PHP is running on. There are: \r \n \r\n Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.