helraizer Posted June 11, 2008 Share Posted June 11, 2008 Hi folks, I have a comment form with textarea, but since the comments go onto an image I don't want them to be able to enter a carriage return/new line. I've tried this: $text = mysql_real_escape_string(htmlspecialchars(stripcslashes(substr($_POST['input'], 0, $rowing['char_count'])))); $text = mysql_real_escape_string(stripcslashes(nl2br($text))); $text = mysql_real_escape_string(stripcslashes(str_replace("<br>", " ", $text))); That, to me get's the truncated message (just incase it's over the character limit), which works. Then it should turn all new lines to a <br> tag then strip said tag. However it still adds the new line. How else could I strip any new line feeds from the $text value? Sam Link to comment https://forums.phpfreaks.com/topic/109732-solved-strip-new-line-tags/ Share on other sites More sharing options...
conker87 Posted June 11, 2008 Share Posted June 11, 2008 $text = mysql_real_escape_string(stripcslashes(str_replace("<br />", "\n", $text))); Might be \n\r or just \r, depending on what OS your server is. Link to comment https://forums.phpfreaks.com/topic/109732-solved-strip-new-line-tags/#findComment-563082 Share on other sites More sharing options...
helraizer Posted June 11, 2008 Author Share Posted June 11, 2008 Each comment is added on one line. However if you add a comment with a carriage return (press enter in the textarea) then it writes it like this: The comment was "new line feed" As you can see, the new is on the line it's supposed to be; then the 'line' is under the third comment and 'feed' is under the 5th. Is it possible to strip the new lines that it's read "New Line Feed" all on one line, even if they added the carriage returns? Hope that makes sense, Sam Link to comment https://forums.phpfreaks.com/topic/109732-solved-strip-new-line-tags/#findComment-563093 Share on other sites More sharing options...
conker87 Posted June 11, 2008 Share Posted June 11, 2008 Oh wait, sorry, lol misread you post. Try: $text = mysql_real_escape_string(stripcslashes(str_replace("\n", "", $text))); Link to comment https://forums.phpfreaks.com/topic/109732-solved-strip-new-line-tags/#findComment-563095 Share on other sites More sharing options...
conker87 Posted June 11, 2008 Share Posted June 11, 2008 Hmm, on second thoughts, do you just want to get rid of ALL HTML? If so, do this: $text = substr($_POST['input'], 0, $rowing['char_count']); $text = strip_tags($text) $text = htmlspecialchars($text) $text = mysql_real_escape_string($text); Link to comment https://forums.phpfreaks.com/topic/109732-solved-strip-new-line-tags/#findComment-563098 Share on other sites More sharing options...
craygo Posted June 11, 2008 Share Posted June 11, 2008 a text area always puts a \r\n for line breaks, so you will have to get rid of both. <?php $text = $_POST['tarea']; $array = array("\r\n", "\n", "\r"); $replace = " "; $newtext = str_replace($array, $replace, $text); ?> Ray Link to comment https://forums.phpfreaks.com/topic/109732-solved-strip-new-line-tags/#findComment-563100 Share on other sites More sharing options...
helraizer Posted June 11, 2008 Author Share Posted June 11, 2008 Works perfectly now, thanks Link to comment https://forums.phpfreaks.com/topic/109732-solved-strip-new-line-tags/#findComment-563119 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.