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 01-06-2008, 03:19 PM   #1 (permalink)
The Acquainted
 
Gareth's Avatar
 
Join Date: Jan 2008
Posts: 136
Thanks: 4
Gareth is on a distinguished road
Default 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.
Gareth is offline  
Reply With Quote
Old 01-06-2008, 08:59 PM   #2 (permalink)
The Contributor
 
Join Date: Dec 2007
Location: Florida
Posts: 73
Thanks: 12
danielneri is on a distinguished road
Default

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 =)
Send a message via AIM to danielneri
danielneri is offline  
Reply With Quote
Old 01-06-2008, 09:17 PM   #3 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 01-06-2008, 09:19 PM   #4 (permalink)
The Contributor
 
Join Date: Dec 2007
Location: Florida
Posts: 73
Thanks: 12
danielneri is on a distinguished road
Default

Yeah thats what I do on my site.

Pull the data from the database, run it through the smilies function, and then output it =)
Send a message via AIM to danielneri
danielneri is offline  
Reply With Quote
Old 01-08-2008, 06:13 PM   #5 (permalink)
The Acquainted
 
Gareth's Avatar
 
Join Date: Jan 2008
Posts: 136
Thanks: 4
Gareth is on a distinguished road
Default

That's indeed what I did in the end.

And for the WYSIWYG editor I am going to use Mootools.
Gareth is offline  
Reply With Quote
Old 01-08-2008, 09:04 PM   #6 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 01-08-2008, 09:15 PM   #7 (permalink)
The Acquainted
 
Gareth's Avatar
 
Join Date: Jan 2008
Posts: 136
Thanks: 4
Gareth is on a distinguished road
Default

Rubbish in what way? Security or..??
Gareth is offline  
Reply With Quote
Old 01-08-2008, 09:24 PM   #8 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 01-08-2008, 09:28 PM   #9 (permalink)
The Addict
Top Contributor Good Samaritan 
 
Join Date: Jan 2008
Location: USA
Posts: 217
Thanks: 16
RobertK is on a distinguished road
Default

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.
__________________
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning. - Rich Cook
RobertK 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 11:40 AM.

 
     

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