wizzkid Posted June 23, 2006 Share Posted June 23, 2006 Hi guys,I know this is a no brainer questions, perhaps there's a trick into my problem.I created add_news.php and view_news.php delete_news.php and edit_news.php, my intention is to add edit delete news to my website. Add, edit, delete has no problem, and was able to do so. However, my problem lies on the article text formatting.you can view my script at:[a href=\"http://www.leeph.net/test/add_news.txt\" target=\"_blank\"]http://www.leeph.net/test/add_news.txt[/a][a href=\"http://www.leeph.net/test/view_news.txt\" target=\"_blank\"]http://www.leeph.net/test/view_news.txt[/a]I assumed that you only need to check the two(2) scripts so I didnt include the edit and delete script.my database info:int_id = BIGINTdate = DATEvc_title = TEXTvc_article = TEXTI am running the follwing:Webserver = Apache 2.0.55-4ubuntu2PHP = PHP 5.1.2-ubuntu3mySQL = MySQL 5.0.22-Debian_0ubuntu6.06PHP5-mysql = 5.1.2-1ubuntu3OS = Kubuntu 6.06 DapperBrowser = Firefox 1.5.0.4 I hope you guys could help me out... Really appreciate your efforts :DThanks. Quote Link to comment https://forums.phpfreaks.com/topic/12726-textarea-text-format/ Share on other sites More sharing options...
kenrbnsn Posted June 23, 2006 Share Posted June 23, 2006 What problems are you having. We really can't help you if you don't let us know what you expect to see and what you are seeing.Ken Quote Link to comment https://forums.phpfreaks.com/topic/12726-textarea-text-format/#findComment-48774 Share on other sites More sharing options...
wildteen88 Posted June 23, 2006 Share Posted June 23, 2006 What do you mean text formatting? Do you mean your text is being displayed in one line, rather than keeping its line breaks that you entered in the textarea?If thats what you mean you'll want to use a function called nl2br which converts \r\n, \n and \r characters into html line breaks (< br />) Quote Link to comment https://forums.phpfreaks.com/topic/12726-textarea-text-format/#findComment-48796 Share on other sites More sharing options...
wizzkid Posted June 23, 2006 Author Share Posted June 23, 2006 [!--quoteo(post=387173:date=Jun 23 2006, 09:30 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 23 2006, 09:30 AM) [snapback]387173[/snapback][/div][div class=\'quotemain\'][!--quotec--]What do you mean text formatting? Do you mean your text is being displayed in one line, rather than keeping its line breaks that you entered in the textarea?If thats what you mean you'll want to use a function called nl2br which converts \r\n, \n and \r characters into html line breaks (< br />)[/quote]Thanks so much wildteen88...Yes, thats right the line break. it was working :) but can I put this on the script? so that the user (the one will enter the article) will not have to type <br/> . is that possible? :) if so, how? :)Then how can I put something like[b] BOLD button [/b][i]ITALICS button[/i] and [u]Underline Button[/u], so the user will just highlight the text and click B, I or U? :)Thank for your help :) Quote Link to comment https://forums.phpfreaks.com/topic/12726-textarea-text-format/#findComment-48812 Share on other sites More sharing options...
hackerkts Posted June 23, 2006 Share Posted June 23, 2006 Yeah, php bbcode.Use this which I'm using:[code]<?phpfunction bbcode($text){$pattern[] = '//';$replace[] = '';$pattern[] = '/\n/';$replace[] = '<br>';$pattern[] = '/\[b\](.*?)\[\/b\]/';$replace[] = '<span style="font-weight:bold">$1</span>';$pattern[] = '/\[i\](.*?)\[\/i\]/';$replace[] = '<span style="font-style:italic">$1</span>';$pattern[] = '/\[u\](.*?)\[\/u\]/';$replace[] = '<span style="text-decoration:underline">$1</span>';$pattern[] = '/\[color=(.*?)\](.*?)\[\/color\]/';$replace[] = '<span style="color: $1">$2</span>';$pattern[] = '/\[url=(.*?)\](.*?)\[\/url\]/';$replace[] = '<a href="$1">$2</a>';$pattern[] = '/\[url\](.*?)\[\/url\]/';$replace[] = '<a href="$1">$1</a>';$pattern[] = '/\[img\](.*?)\[\/img\]/';$replace[] = '<img src="$1">';$pattern[] = '/\[b\](.*?)\[\/b\]/';$replace[] = '<b>$1</b>';$text = preg_replace($pattern, $replace, $text);return $text;}?>[/code]So when you echo out your news, remember to use the function.[b]bbcode()[/b] Quote Link to comment https://forums.phpfreaks.com/topic/12726-textarea-text-format/#findComment-48814 Share on other sites More sharing options...
wildteen88 Posted June 23, 2006 Share Posted June 23, 2006 [!--quoteo(post=387190:date=Jun 23 2006, 04:09 PM:name=wizzkid)--][div class=\'quotetop\']QUOTE(wizzkid @ Jun 23 2006, 04:09 PM) [snapback]387190[/snapback][/div][div class=\'quotemain\'][!--quotec--]Thanks so much wildteen88...Yes, thats right the line break. it was working :) but can I put this on the script? so that the user (the one will enter the article) will not have to type <br/> . is that possible? :) if so, how? :)Then how can I put something like[b] BOLD button [/b][i]ITALICS button[/i] and [u]Underline Button[/u], so the user will just highlight the text and click B, I or U? :)Thank for your help :)[/quote]You use the nl2br function on the variable that stores the news article, which I believe is $row['vc_article'] in view_news.txt. So you'll do this:[code]nl2br($row['vc_article']);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12726-textarea-text-format/#findComment-48818 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.