shadiadiph Posted December 29, 2008 Share Posted December 29, 2008 Hi I in my form I am calling data from the database already stored. This is probably a simple solution but I have no idea what it is. <tr><td><span id="t_description">DESCRIPTION</span></td></tr> <tr><td><textarea name="description"><? print $description; ?></textarea></td></tr> the problem is that it is displaying steel metal ones<br /> plastic ones the <br /> is not supposed to display how can i display this without the <br/> tag? The data entered by the user did have a line break but not a visible one? Quote Link to comment https://forums.phpfreaks.com/topic/138792-solved-displaying-text-problem-unwanted-break/ Share on other sites More sharing options...
flyhoney Posted December 29, 2008 Share Posted December 29, 2008 At some point nl2br() is being called on the input text, and then htmlspecialchars() or htmlentities() is being called on that. Try this: <tr><td><span id="t_description">DESCRIPTION</span></td></tr> <tr><td><textarea name="description"><? print html_entity_decode($description); ?></textarea></td></tr> Quote Link to comment https://forums.phpfreaks.com/topic/138792-solved-displaying-text-problem-unwanted-break/#findComment-725705 Share on other sites More sharing options...
premiso Posted December 29, 2008 Share Posted December 29, 2008 Are you using nl2br anywhere? If you are remove that. As for converting it back...str_replace should do it. $string = "string with <br />"; $string = str_replace("<br />", "\n", $string); echo $string; Should get you what you want. Quote Link to comment https://forums.phpfreaks.com/topic/138792-solved-displaying-text-problem-unwanted-break/#findComment-725708 Share on other sites More sharing options...
shadiadiph Posted December 29, 2008 Author Share Posted December 29, 2008 mm that doesn't work yes you are right when the data gets saved it uses nl2br() to make sure the data is formated in the way it was entered by the user just need to know how to unformat that code.? when I save it i am passing the data to be inserted to the database i am using $description =(nl2br($_POST["description"])); Quote Link to comment https://forums.phpfreaks.com/topic/138792-solved-displaying-text-problem-unwanted-break/#findComment-725710 Share on other sites More sharing options...
premiso Posted December 29, 2008 Share Posted December 29, 2008 Wow, do not use nl2br to save buddy. You only use that to display data. If you use it to save you come across the problem that it is much harder to reverse that. Which is why you always save data in it's raw format. Not the displayed format. Fix that problem and you will not have this issue later on. Then use nl2br when you need it on displaying the data. Quote Link to comment https://forums.phpfreaks.com/topic/138792-solved-displaying-text-problem-unwanted-break/#findComment-725711 Share on other sites More sharing options...
flyhoney Posted December 29, 2008 Share Posted December 29, 2008 You need to use nl2br() when you want to output the text, it is better to save the text in its raw state. I would remove the nl2br() on the save and just use it when you need to display the text. Quote Link to comment https://forums.phpfreaks.com/topic/138792-solved-displaying-text-problem-unwanted-break/#findComment-725713 Share on other sites More sharing options...
shadiadiph Posted December 29, 2008 Author Share Posted December 29, 2008 I took out the nl2br when i display the text by calling it from the database the forst time using $description = $row["description"]; <tr><td><textarea name="description"><? print $description; ?></textarea></td></tr> it diplays normally i then saved the page exactly the same and when it reloads to the second page onchange it starts showing the <br /> tags again makes no sense as the coding is he same?? Quote Link to comment https://forums.phpfreaks.com/topic/138792-solved-displaying-text-problem-unwanted-break/#findComment-725731 Share on other sites More sharing options...
shadiadiph Posted December 29, 2008 Author Share Posted December 29, 2008 just tried this $description = (nl2br($row["description"])); doesn't work? Quote Link to comment https://forums.phpfreaks.com/topic/138792-solved-displaying-text-problem-unwanted-break/#findComment-725736 Share on other sites More sharing options...
flyhoney Posted December 29, 2008 Share Posted December 29, 2008 I don't really understand what you mean. You just need to make sure that you are saving the description in its raw state, without calling nl2br(). That way, you will always have "\n" in your database and whenever you want to display the formatted text, use nl2br(). Quote Link to comment https://forums.phpfreaks.com/topic/138792-solved-displaying-text-problem-unwanted-break/#findComment-725741 Share on other sites More sharing options...
shadiadiph Posted December 29, 2008 Author Share Posted December 29, 2008 I am now saving it as raw data but when I call it normall on one page it displays no br tags and with the same coding on another page it displays the br tags I have tried using nl2br() when calling the row from the database but it still displays with br tags? Quote Link to comment https://forums.phpfreaks.com/topic/138792-solved-displaying-text-problem-unwanted-break/#findComment-725744 Share on other sites More sharing options...
flyhoney Posted December 29, 2008 Share Posted December 29, 2008 Using nl2br() will replace "\n" with "<br />". So if you don't want "<br />", don't use nl2br(). Quote Link to comment https://forums.phpfreaks.com/topic/138792-solved-displaying-text-problem-unwanted-break/#findComment-725748 Share on other sites More sharing options...
shadiadiph Posted December 29, 2008 Author Share Posted December 29, 2008 sorry i got confused i though i had to use it somewhere now i am not using it anywhere everything works fine thanks. Quote Link to comment https://forums.phpfreaks.com/topic/138792-solved-displaying-text-problem-unwanted-break/#findComment-725765 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.