tutorial on how to make the bb-code insert editor?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

tutorial on how to make the bb-code insert editor?

Post by kendall »

Hi guys,

Uhm i am trying to learn how you guys created this application for me to use the "[b]""[b]" when posting this topic. What do you call it and html editor? or html processor?

anyone no where i can get a tut on it?

Kendall
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

phpbb

Post by phpScott »

i believe it is all part of the phpbb system that you can get from http://www.phpbb.com/
so you can get the code, rip it apart and do what you like with it.
Other wise i think it has to do with regex and the like.
not having seen the code I don't know.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's a simple [php_man]preg_replace[/php_man]() call.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

It's called bbcode so that's what you want to be looking for in the phpBB code or when you're looking for tutorials :)

Mac
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

if you don't feel like ripping it from phpbb, you can also use the pear package..

some sample code: http://home.mysth.be/~timvw/programming ... syform.zip
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

example code I use:

Code: Select all

<?php
function smile($string) { 
  $ex[]  = '/:\)(?!\))/';    
  $img[] = '<img src=faces/smile.gif>'; 
   
  $ex[]  = '/:\((?!\()/';    
  $img[] = '\\1<img src=faces/sad.gif>'; 

  $ex[]  = '/:mad:/';    
  $img[] = '<img src=faces/mad.gif>'; 

foreach($ex as $key => $value) { 
        $string = preg_replace($value, $img[$key], $string); 
    } 
?>
simple rpeg replca like good ole feyd said. You can use text or find the actual smile n replace.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

To make an actual editor, I'd take a look at the phpBB javascript and learn from there.

Or you can always simply copy+paste and leave the credit and link to the GPL. ;)

...not that I ever do that or anything... 8O :wink:
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

tim wrote:

Code: Select all

<?php
function smile($string) { 
  $ex[]  = '/:\)(?!\))/';    
  $img[] = '<img src=faces/smile.gif>'; 
   
  $ex[]  = '/:\((?!\()/';    
  $img[] = '\\1<img src=faces/sad.gif>'; 

  $ex[]  = '/:mad:/';    
  $img[] = '<img src=faces/mad.gif>'; 

foreach($ex as $key => $value) { 
        $string = preg_replace($value, $img[$key], $string); 
    } 
?>
I just do

Code: Select all

<?php

  $ex[]  = '/:\((?!\()/';    
  $img[] = '\\1<img src=faces/sad.gif>'; 

  $ex[]  = '/:mad:/';    
  $img[] = '<img src=faces/mad.gif>'; 

  $string = preg_replace($ex, $img, $string); 
 
?>
since preg_replace can handle arrays ;)
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

Uhm sorry guys i think youre missing my question....you see the form that we use to post messages....? i was wondering how they were able to allo wme to do "[b]" if i wanted to get the text to output bold. i have taken a look at the form and i am figuring it oout...thanks for the help. However i dont know why the cursor is not being repositioned after adding "[b]bold[/b]" to the textarea

Kendall
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

okay, now, I have no idea what you are actually asking.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Aah, you're looking at the JS stuff? I'd ask any questions in the client-side forum then :)

Mac
Post Reply