Jump to content


Photo

Textarea Text Format


  • Please log in to reply
5 replies to this topic

#1 wizzkid

wizzkid
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 23 June 2006 - 01:13 PM

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.

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 23 June 2006 - 01:22 PM

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

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 23 June 2006 - 02:30 PM

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 />)

#4 wizzkid

wizzkid
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 23 June 2006 - 03:09 PM

[!--quoteo(post=387173:date=Jun 23 2006, 09:30 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 23 2006, 09:30 AM) View Post[/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 BOLD button ITALICS button and Underline Button, so the user will just highlight the text and click B, I or U? :)

Thank for your help :)



#5 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 23 June 2006 - 03:13 PM

Yeah, php bbcode.
Use this which I'm using:
<?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;
}

?>

So when you echo out your news, remember to use the function.
bbcode()

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 23 June 2006 - 03:32 PM

[!--quoteo(post=387190:date=Jun 23 2006, 04:09 PM:name=wizzkid)--][div class=\'quotetop\']QUOTE(wizzkid @ Jun 23 2006, 04:09 PM) View Post[/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 BOLD button ITALICS button and Underline Button, 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:
nl2br($row['vc_article']);





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users