Manixat Posted April 12, 2013 Share Posted April 12, 2013 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 ... Link to comment https://forums.phpfreaks.com/topic/276867-cleaning-new-lines/ 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. Link to comment https://forums.phpfreaks.com/topic/276867-cleaning-new-lines/#findComment-1424364 Share on other sites More sharing options...
Manixat Posted April 12, 2013 Author 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. Link to comment https://forums.phpfreaks.com/topic/276867-cleaning-new-lines/#findComment-1424367 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 Link to comment https://forums.phpfreaks.com/topic/276867-cleaning-new-lines/#findComment-1424375 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.