XeroXer Posted July 27, 2006 Share Posted July 27, 2006 Hi there...This is my problem:I am making a guestbook that uses a flat file.Just a simple one for my mother-in-law's homepage.The problem I am having is that when people enter a two rowed message the file bugs out.Well they can enter a two-row message if they just type and type.But as quickly as they press enter to change the row it doesn't work.They can still post the message but in the textfile that just makes a new line and I would like it to change it to:[code]<br>[/code]So what I would like to know is if I can get a normal 'enter' in a textarea to become a [code]<br>[/code] in the textfile?Plz help... ;D Quote Link to comment https://forums.phpfreaks.com/topic/15815-row-changes-in-textare/ Share on other sites More sharing options...
wildteen88 Posted July 27, 2006 Share Posted July 27, 2006 You'll want to use nl2br, it converts newlines into html line breaks. The newlines are there still but the browser ignores them Quote Link to comment https://forums.phpfreaks.com/topic/15815-row-changes-in-textare/#findComment-64712 Share on other sites More sharing options...
XeroXer Posted July 27, 2006 Author Share Posted July 27, 2006 Well thanks. That added the [code]<br>[/code] that I wanted.Though it did not remove the line added.The message still winds up in multiple rows in the textfile but now with [code]<br>[/code] after them.So that helped in someway but I still need the linebreaker that comes with 'enter' removed...[b]EDIT:[/b]I also need it to add a [code]<br>[/code] like a automatic linebreaker.If a person just types a loooooong message without any space the site expands.Is it possible to make it do automatic linebreaker if no space is found? Quote Link to comment https://forums.phpfreaks.com/topic/15815-row-changes-in-textare/#findComment-64715 Share on other sites More sharing options...
wildteen88 Posted July 27, 2006 Share Posted July 27, 2006 Do somtyhing like this:[code]$text = str_replace(array("\r", "\n"), '', $text);[/code]That'll remove the newlines. Make sure you use this after nl2br, otherwise nl2br wont work. Quote Link to comment https://forums.phpfreaks.com/topic/15815-row-changes-in-textare/#findComment-64716 Share on other sites More sharing options...
XeroXer Posted July 27, 2006 Author Share Posted July 27, 2006 OMG that did the trick.Now they can press enter how many times they want.The message will still be presented the right way...Though the problem I edited in the other message can that be solved? Quote Link to comment https://forums.phpfreaks.com/topic/15815-row-changes-in-textare/#findComment-64717 Share on other sites More sharing options...
wildteen88 Posted July 27, 2006 Share Posted July 27, 2006 You'll want to use wordwarp:[code]<?php$text = "ttttttttttttttttttthhhhhhhhhhhhhhhhhhhhhhhhhhhiiiiiiiiiiiiiiiiiiiiiiiiissssssssssssssssssssssss aaaaaaaaaaaaaaaaa lllllllllllllllllllllllllllllllllllllllllllloooooooooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnngggggggggggggggggggggggggggggggg pppppppppppppppppppppppppppppppppppppppppppppppppppoooooooooooooooooooooooooooooooooooooooooooooooooooooooosssssssssssssssssssssssssssssssssssssssssssssssssssssstttttttttttttt.";$newtext = wordwrap($text, 200, "<br />", true);echo $newtext;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15815-row-changes-in-textare/#findComment-64718 Share on other sites More sharing options...
XeroXer Posted July 27, 2006 Author Share Posted July 27, 2006 Thank you once again.Now my guestbook works like a charm... :-) Quote Link to comment https://forums.phpfreaks.com/topic/15815-row-changes-in-textare/#findComment-64735 Share on other sites More sharing options...
XeroXer Posted July 28, 2006 Author Share Posted July 28, 2006 [size=12pt][u][color=red][b]NEW QUESTION![/b][/color][/u][/size]Now I have another question still regarding my guestbook.Thought I'd post it here instead of creating a new thread.Now my flatfile guestbooks work almost as I want it.I have gotten control over the length of the text entered.I also got so it supports pressing 'enter' while writing a message.Now I need it to remove the html code and anything similar. :-)I want to strip the html code from the message before entering it into the textfile.Or just print it out plain html and not working.Because now people can enter what they like and ruin my guestbook.A javascript that makes something annoying or a few rows of html that changes everything.So please help me.[b]1)[/b] How do i strip of the html code before entering it into the file?[b]2)[/b] How do I print the file with the code intact but not working?[b]3)[/b] Witch one of these do you think I should use? Quote Link to comment https://forums.phpfreaks.com/topic/15815-row-changes-in-textare/#findComment-65091 Share on other sites More sharing options...
wildteen88 Posted July 28, 2006 Share Posted July 28, 2006 To strip any html tags use the function called strip_tags, also use other functions called htmlspecialchars, htmlentities and addslashes. Quote Link to comment https://forums.phpfreaks.com/topic/15815-row-changes-in-textare/#findComment-65093 Share on other sites More sharing options...
XeroXer Posted July 28, 2006 Author Share Posted July 28, 2006 I have to use them all?I was going to check the quickref on php.net but the site is down as it seems.So I need the info on the functions. :-( Quote Link to comment https://forums.phpfreaks.com/topic/15815-row-changes-in-textare/#findComment-65102 Share on other sites More sharing options...
wildteen88 Posted July 28, 2006 Share Posted July 28, 2006 We have the php manual on the main site, phpfreaks.comHere are links to those functions:[url=http://www.phpfreaks.com/phpmanual/page/function.htmlentities.html]htmlentities[/url][url=http://www.phpfreaks.com/phpmanual/page/function.htmlspecialchars.html]htmlspecialchars[/url][url=http://www.phpfreaks.com/phpmanual/page/function.strip-tags.html]strip_tags[/url] Quote Link to comment https://forums.phpfreaks.com/topic/15815-row-changes-in-textare/#findComment-65104 Share on other sites More sharing options...
XeroXer Posted July 28, 2006 Author Share Posted July 28, 2006 If I use htmlentities and strip_tags on all fields will they still work?Name, Email, Homepage and Message.Those fields are in my guestbook.If I use both those functions on all those fields will still long homepage and mail adresses work? Quote Link to comment https://forums.phpfreaks.com/topic/15815-row-changes-in-textare/#findComment-65107 Share on other sites More sharing options...
wildteen88 Posted July 28, 2006 Share Posted July 28, 2006 Yes. As those function will stripout any html from those fields, and htmlentities will convert some hmtls characters into their HTML equivalent, for exampe an opeing triangle barcket < will be converted < Quote Link to comment https://forums.phpfreaks.com/topic/15815-row-changes-in-textare/#findComment-65109 Share on other sites More sharing options...
XeroXer Posted July 28, 2006 Author Share Posted July 28, 2006 Just one last thing... :-)Is there any special order these should be taken in?Or can I make somethings do more on one row?This is my code for the message field right now:[code]<?php//Set message$message = $_POST["message"];$message = strip_tags($message);$message = htmlentities($message, ENT_QUOTES);$message = nl2br("$message");$message = str_replace(array("\r", "\n"), '', $message);$message = wordwrap($message, 50, "<br />", true);?>[/code]And for name, email and homepage it's this:[code]<?php//Set name$name = $_POST["name"];$name = strip_tags($name);$name = htmlentities($name, ENT_QUOTES);$name = wordwrap($name, 50, "<br />", true);//Set email$email = $_POST["email"];$email = strip_tags($email);$email = htmlentities($email, ENT_QUOTES);$email = wordwrap($email, 50, "<br />", true);//Set homepage$homepage = $_POST["homepage"];$homepage = strip_tags($homepage);$homepage = htmlentities($homepage, ENT_QUOTES);$homepage = wordwrap($homepage, 50, "<br />", true);?>[/code]Does that look good or not?The message field is the only one that is a textarea. The other ones are just a "textrow".That is why I don't use the nl2br and str_replace with name, email or homepageIs that correct? Quote Link to comment https://forums.phpfreaks.com/topic/15815-row-changes-in-textare/#findComment-65114 Share on other sites More sharing options...
wildteen88 Posted July 28, 2006 Share Posted July 28, 2006 Rather than doing each function seperatly, I'd do it all in one line.[code]//Set name$name = htmlentities(strip_tags($_POST['name']));[/code]Also for each text field, I'd add the maxlength attribute to set the maxumin number of characters for each field. Then you dont need to use wordwrap. Quote Link to comment https://forums.phpfreaks.com/topic/15815-row-changes-in-textare/#findComment-65156 Share on other sites More sharing options...
XeroXer Posted July 28, 2006 Author Share Posted July 28, 2006 Thanks!My rows now look like this:[code]<?php//Set name$name = htmlentities(strip_tags($_POST['name']));//Set email$email = htmlentities(strip_tags($_POST['email']));//Set homepage$homepage = htmlentities(strip_tags($_POST['homepage']));//Set message$message = nl2br(htmlentities(strip_tags($_POST['message'])));$message = str_replace(array("\r", "\n"), '', $message);$message = wordwrap($message, 50, "<br />", true);?>[/code]That looks a lot better and I also added the lengthlimit on the textfields.Thanks for all the help.Will be back for more questions regarding other stuff :-) Quote Link to comment https://forums.phpfreaks.com/topic/15815-row-changes-in-textare/#findComment-65215 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.