pgrevents Posted April 25, 2009 Share Posted April 25, 2009 What I am trying to do is basicly (hopefully) is i am creating a bio part for my website and it will be saving to a mysql database. What I want to recreate is how the user typed it in such as spaces and line breaks like <br/> etc. If the user hits enter and creates a new paragraph in essence i want the php to add the <br/> I hope in reading this you understand what I am trying to get across cause I dont lol Does anyone have any ideas cheers Paul Link to comment https://forums.phpfreaks.com/topic/155660-solved-adding-line-breaks/ Share on other sites More sharing options...
ialsoagree Posted April 25, 2009 Share Posted April 25, 2009 http://us.php.net/nl2br Link to comment https://forums.phpfreaks.com/topic/155660-solved-adding-line-breaks/#findComment-819274 Share on other sites More sharing options...
pgrevents Posted April 25, 2009 Author Share Posted April 25, 2009 basicly the user will be entering into a normal text area form element and it recreates exactly what the user has typed??? Link to comment https://forums.phpfreaks.com/topic/155660-solved-adding-line-breaks/#findComment-819275 Share on other sites More sharing options...
ialsoagree Posted April 25, 2009 Share Posted April 25, 2009 That website goes over how to do exactly what you describe: <?php $formatted_submission = nl2br($unformatted_submission); ?> Link to comment https://forums.phpfreaks.com/topic/155660-solved-adding-line-breaks/#findComment-819279 Share on other sites More sharing options...
pgrevents Posted April 26, 2009 Author Share Posted April 26, 2009 sorry for the delay what a simple solution lol thanks... now how would one remove the line breaks from showing in the text area for example updating the entered text? thanks again. Link to comment https://forums.phpfreaks.com/topic/155660-solved-adding-line-breaks/#findComment-819781 Share on other sites More sharing options...
KPH71 Posted April 26, 2009 Share Posted April 26, 2009 <?php str_replace("<br>", "\n", $string); ?> Link to comment https://forums.phpfreaks.com/topic/155660-solved-adding-line-breaks/#findComment-819800 Share on other sites More sharing options...
wildteen88 Posted April 26, 2009 Share Posted April 26, 2009 sorry for the delay what a simple solution lol thanks... now how would one remove the line breaks from showing in the text area for example updating the entered text? thanks again. You should use nl2br when you display the text to screen. That way you wonthave to convert the <br /> tags with \n, which just over complicates things Link to comment https://forums.phpfreaks.com/topic/155660-solved-adding-line-breaks/#findComment-819801 Share on other sites More sharing options...
pgrevents Posted April 26, 2009 Author Share Posted April 26, 2009 i never thought of that what i done was removed them using ereg_replace function but that sounds much better and probably more of a space saver in the long run. thanks Link to comment https://forums.phpfreaks.com/topic/155660-solved-adding-line-breaks/#findComment-819803 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.