Jump to content

Archived

This topic is now archived and is closed to further replies.

wizzkid

Textarea Text Format

Recommended Posts

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 = BIGINT
date = DATE
vc_title = TEXT
vc_article = TEXT

I am running the follwing:
Webserver = Apache 2.0.55-4ubuntu2
PHP = PHP 5.1.2-ubuntu3
mySQL = MySQL 5.0.22-Debian_0ubuntu6.06
PHP5-mysql = 5.1.2-1ubuntu3
OS = Kubuntu 6.06 Dapper
Browser = Firefox 1.5.0.4


I hope you guys could help me out... Really appreciate your efforts :D

Thanks.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 />)

Share this post


Link to post
Share on other sites
[!--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 :)

Share this post


Link to post
Share on other sites
Yeah, php bbcode.
Use this which I'm using:
[code]<?php

function 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]

Share this post


Link to post
Share on other sites
[!--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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.