TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-04-2008, 06:08 PM   #1 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default hey i ned help on BBcode

hey , i wanna use bbcode on my script (textarea)
i wanna allow visitors to make text bold and add photos , things like that
so how can i do that ??
i really need help on that
thanks !!
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 03-04-2008, 06:19 PM   #2 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

The basic process is fairly straightforward - your script just searches for the BBCode tag and replaces it with the HTML equivelent.

For example, for bold it would search for [b] and replace it with <strong>.

It can get complex when you start dealing with complex BBCode (for example, Invision Board's BBCode parser comes in at just under 4,000 lines of code) but don't worry about that for now

Also, there is a BBCode extension which may help - PHP: BBCode - Manual

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 03-04-2008, 06:23 PM   #3 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default

thanks im using this code but it didnt succeed =>
$t=str_replace("[b]", "<b>", $text);
$text = htmlentities($tuto['message']);
if($v = eregi('<' , $string)){
echo "no html cods";
}

and the output i show it on another page , but it give blank page
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 03-04-2008, 06:26 PM   #4 (permalink)
The Contributor
 
abiko's Avatar
 
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
abiko is on a distinguished road
Default

Here is a nice BBcode class - with documentation :)
__________________
Back from sysadmins to the programmers.
Send a message via ICQ to abiko Send a message via MSN to abiko
abiko is offline  
Reply With Quote
Old 03-04-2008, 07:07 PM   #5 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default

ah i tried this class but i think i didnt know how to use even of the documentation
could you explain to me how to use this class

i did that =>
require_once 'stringparser_bbcode.class.php';


and i copy everything to my folder
but nothing :s
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 03-04-2008, 08:00 PM   #6 (permalink)
The Acquainted
 
Gareth's Avatar
 
Join Date: Jan 2008
Posts: 136
Thanks: 4
Gareth is on a distinguished road
Default

I sent you a PM with an answer.
Gareth is offline  
Reply With Quote
Old 03-04-2008, 08:43 PM   #7 (permalink)
The Acquainted
 
Gareth's Avatar
 
Join Date: Jan 2008
Posts: 136
Thanks: 4
Gareth is on a distinguished road
Default

Ahh, do you mean a WYSIWYG editor?
Gareth is offline  
Reply With Quote
Old 03-07-2008, 12:14 PM   #8 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default

Quote:
Originally Posted by Gareth View Post
Ahh, do you mean a WYSIWYG editor?
YEAH I MEAN WYSIWYG editor
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 03-05-2008, 09:17 PM   #9 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Gareth, unless there's any particular reason why the answer needs to be private, I'm sure it would benefit the whole community if all answers were posted publicly. It provides a flow of conversation and an archive of information for people coming back to look at this topic in the future.
Salathe is offline  
Reply With Quote
Old 03-07-2008, 05:52 PM   #10 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

If you want a WYSIWYG editor I would recomend using - TinyMCE Javascript Content Editor by Moxiecode Systems AB - it's fully functional with plenty of documentation and example code

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 03-20-2008, 10:54 AM   #11 (permalink)
The Contributor
 
marxx's Avatar
 
Join Date: Sep 2007
Location: Finland
Posts: 45
Thanks: 3
marxx is on a distinguished road
Default

Well, if you end up using simple function (or someone else need help whit it) here is one simple parser.

PHP Code:
function bbcode_format($var) {
    
$search = array(
        
'/\[b\](.*?)\[\/b\]/is',                                
        
'/\[i\](.*?)\[\/i\]/is',                                
        
'/\[u\](.*?)\[\/u\]/is',
        
'/\[img\](.*?)\[\/img\]/is',
        
'/\[url\](.*?)\[\/url\]/is',
        
'/\[url\=(.*?)\](.*?)\[\/url\]/is'
        
);

    
$replace = array(
        
'<strong>$1</strong>',
        
'<em>$1</em>',
        
'<u>$1</u>',
        
'<img src="$1" />',
        
'<a href="$1">$1</a>',
        
'<a href="$1">$2</a>'
        
);

    
$var preg_replace ($search$replace$var);

    return 
$var;

usage:
PHP Code:

$text 
"This is [b]example[/b] text whit
 [url=http://www.google.com]google link[/url]"
;

echo 
bbcode_format($text); 
will look like:

This is example text whit google link.

=)
Send a message via MSN to marxx
marxx is offline  
Reply With Quote
The Following 2 Users Say Thank You to marxx For This Useful Post:
Alan @ CIT (03-23-2008), ETbyrne (03-20-2008)
Old 03-20-2008, 04:45 PM   #12 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

Wow, great job marxx! I've got to try this.
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:49 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design