Jump to content

Textarea Text Format


wizzkid

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.
Link to comment
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 />)
Link to comment
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 :)

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.