TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Custom BBCode / WYSIWYG (http://www.talkphp.com/absolute-beginners/1875-custom-bbcode-wysiwyg.html)

Gareth 01-06-2008 03:19 PM

Custom BBCode / WYSIWYG
 
Hi

A few of you might know about my SBB forum software which I am making. Well, simply put, is there an easy way I can make my own bbcode with a simple WYSIWYG editor type thing (not important, could be just input buttons which when pressed enters part of a bbcode into the text box)?

I have a static method; found on the internet:

PHP Code:

<?php 

function smilies($text){
    
     
$smilies['plaintext'] = array(":)",":D",":(");
     
$smilies['htmltext'] = array("<img src='happy.png'>","<img src='grin.png'>","<img src='sad.png'>");
     
     
$text str_replace($smilies['plaintext'],
     
$smilies['htmltext'],$text);
     
     return 
$text; }
     
    echo 
smilies("Hello bob :) :D "); 
      
    
?>

Could I just run this function through the mysql query?

Also could someone tell me how I would use the function nl2br to make it so that when the user makes a new line in the text box it puts a <br / > tag there?

Gareth.

danielneri 01-06-2008 08:59 PM

What do you mean by run it through a query?

And as far as nl2br, say $text was the user's input, just use $text = nl2br($text); and it should work just fine.

For a WYSIWYG editor, just have a row of buttons that, when clicked, adds that code to the text field. Most of the editors nowadays use Javascript, and I'm pretty sure thats the only way to do it without reloading the page.
This might help: How to Create a WYSIWYG Rich Text Editor in JavaScript. Pt. 1 - WebReference.com-

Hope that helped =)

Wildhoney 01-06-2008 09:17 PM

Do you mean run the smilies function through the return results from the query? So in your case an individual's post. If that is what you're asking then that's perfectly acceptable.

danielneri 01-06-2008 09:19 PM

Yeah thats what I do on my site.

Pull the data from the database, run it through the smilies function, and then output it =)

Gareth 01-08-2008 06:13 PM

That's indeed what I did in the end.

And for the WYSIWYG editor I am going to use Mootools.

Wildhoney 01-08-2008 09:04 PM

Ooo MooTools. Is that such a good idea knowing how rubbish MooTools is? Personally speaking. I may be tempted to use Scriptalicious if you can.

Gareth 01-08-2008 09:15 PM

Rubbish in what way? Security or..??

Wildhoney 01-08-2008 09:24 PM

No no. Not security. I think it's just very bad in the way it implements things. I would consider it more of a scripting library than a programmers' library. But that's just my personal preference. MooTools just doesn't promote good coding practices from what I have witnessed of it.

RobertK 01-08-2008 09:28 PM

I happen to have used it, and I quite like it. Some of its internal code might be sloppy, sure, but it is quite efficient and has the smoothest effects. To each their own.


All times are GMT. The time now is 07:29 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0