Page 1 of 1

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

Posted: Thu Oct 07, 2004 10:49 am
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

phpbb

Posted: Thu Oct 07, 2004 10:59 am
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.

Posted: Thu Oct 07, 2004 11:00 am
by feyd
it's a simple [php_man]preg_replace[/php_man]() call.

Posted: Thu Oct 07, 2004 1:13 pm
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

Posted: Thu Oct 07, 2004 3:21 pm
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

Posted: Thu Oct 07, 2004 6:19 pm
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.

Posted: Thu Oct 07, 2004 9:21 pm
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:

Posted: Fri Oct 08, 2004 8:45 am
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 ;)

Posted: Fri Oct 08, 2004 9:22 am
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

Posted: Fri Oct 08, 2004 9:52 am
by feyd
okay, now, I have no idea what you are actually asking.

Posted: Fri Oct 08, 2004 10:07 am
by twigletmac
Aah, you're looking at the JS stuff? I'd ask any questions in the client-side forum then :)

Mac