October 1, 20187 yr Hello everyone, I am currently developing a forum and we decided to use a html editor to post threads at first. We have changed our minds and decided that we only want to allow BB code. So we have bb codes for like bold, italic, new line. horizontal line etc. So we want to add something above the text area. Like a button with a B I or underscored U on the top of this html editor. And when the user clicks on the B for example, it should add to the textarea. I think this could be done with javascript? My textarea on the edit thread page: <a href="#"">Bold </a> // So when the user clicks this, it should add [b][/b] to the end of the textarea below without changing the content that is already in the textarea. <textarea id="editor1" name="editor1EDIT" rows="10" cols="80">'.$getthethreadcontent.'</textarea> Im really a noob at javascript so any advice on how to do this would be helpful. If there are any other methods then javascript i am willing to hear it.
October 1, 20187 yr I'd be inclined to use a ready-made solution. It's going to perform better and be much easier. I've used SCEditor in the past. It's fairly decent: https://www.sceditor.com/ It comes with loads of options (buttons on the toolbar). If you only want the ones listed above, check out this page on the documentation to limit the options: https://www.sceditor.com/documentation/options/ Edited October 1, 20187 yr by Fee
October 1, 20187 yr Author Edit: About SCEditor... I currently am trying it out and sofar its exactly what i need except.. http://losangeles-roleplay.org/example.html When you type test. Press enter for new line it doesn't add a [br]? Shouldn't it do that automatically? Thanks. So is there also something to process bb code? Currently doing it like this: // bb to html $getthethreadcontent = htmlspecialchars($getthethreadcontent); $getthethreadcontent = str_replace('[url="','<a href="', $getthethreadcontent); $getthethreadcontent = str_replace('"]','">', $getthethreadcontent); $getthethreadcontent = str_replace('[/url]','</a>', $getthethreadcontent); $getthethreadcontent = str_replace('[br]','</br>', $getthethreadcontent); //html to bb $getthethreadcontent = htmlspecialchars($getthethreadcontent); $getthethreadcontent = str_replace('<a href="','[url="', $getthethreadcontent); $getthethreadcontent = str_replace('">','"]', $getthethreadcontent); $getthethreadcontent = str_replace('</a>','[/url]', $getthethreadcontent); $getthethreadcontent = str_replace('</br>','[br]', $getthethreadcontent); Edited October 1, 20187 yr by ChubbyKakert
October 1, 20187 yr I've never used sceditor in the past, but i've had a lot of good experience with tinyMCE: https://www.tiny.cloud/ Just another one to consider!
October 2, 20187 yr 19 hours ago, ChubbyKakert said: $getthethreadcontent = str_replace('[br]','</br>', $getthethreadcontent); Should that not be <br> for html? Edited October 2, 20187 yr by BrowserBugs
October 5, 20187 yr Author On 10/2/2018 at 12:22 PM, BrowserBugs said: Should that not be <br> for html? I think both do work.
October 5, 20187 yr Cool was the only thing I could spot that looked different and you had mentioned the line break issue. I remember an old project that had two different ways stuff had been saved, ended up with a work around swapping with actual characters so we could output both <p> and <br> correctly. function revrn($var) { return str_replace(array(chr(13), chr(10)), array('\r', '\n'), $var); } Edited October 5, 20187 yr by BrowserBugs
Create an account or sign in to comment