Hartley Posted December 11, 2006 Share Posted December 11, 2006 I have a form that runs through a validation then enters a MYSQL database. To get the syntax right, I had to do a couple PHP functions to make sure it would parse correctly visually and, in the event of any funny characters, ensure it doesn't crash the function.[code]$anythingelse = stripslashes(strip_tags($_POST['anythingelse']));$anythingelse = nl2br($anythingelse);[/code]The anythingelse is a textbox that I'm setting as a variable for later. The nl2br is to make sure the line breaks are properly registered for the visual part. Later on, I have a hidden form to submit, and it will then go to be processed:[code]$anythingelse = htmlspecialchars($_POST['anythingelse']);[/code]This was to get rid of any problems putting it into the database. However, if anyone put a line break into the function, I would get something like this:<br /><br />I see that it parsed a first <br /> into special characters, but a second line break sort of appeared out of nowhere, and I can't figure out how. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
btherl Posted December 11, 2006 Share Posted December 11, 2006 To avoid this problem, only use nl2br() when you are displaying the data. Keep another copy of the data before nl2br(), and put that copy into the database.You may have to have 2 form variables, one displayed and one hidden. Quote Link to comment Share on other sites More sharing options...
Hartley Posted December 11, 2006 Author Share Posted December 11, 2006 Ahh, that seemed to do the trick. I tested and it seemed to work fine: I'll let it go public for a bit and see if anything turns up. Thanks again! 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.