I'm developing my own CMS (for my clientes) and I want to use WysiBB ( http://www.wysibb.com/ ) for text areas. But the thing is that WysiBB saves html tags with [ ] instead of < > (ex. [h1]Text[/h1]) and then, the website doesn't recognise the [ ] tags. What should I do?
I need to thank @isherwood for the help he gave me! Didn't realise that WysiBB was a BBcode editor cause I never heard about BBcode. What I did? I've implemented a function to convert BBCode to HTML.
//======================== START OF FUNCTION ==========================//
// FUNCTION: bbcode_to_html //
//=====================================================================//
function bbcode_to_html($bbtext){
$bbtags = array(
'[heading1]' => '<h1>','[/heading1]' => '</h1>',
'[heading2]' => '<h2>','[/heading2]' => '</h2>',
'[heading3]' => '<h3>','[/heading3]' => '</h3>',
'[h1]' => '<h1>','[/h1]' => '</h1>',
'[h2]' => '<h2>','[/h2]' => '</h2>',
'[h3]' => '<h3>','[/h3]' => '</h3>',
'[paragraph]' => '<p>','[/paragraph]' => '</p>',
'[para]' => '<p>','[/para]' => '</p>',
'[p]' => '<p>','[/p]' => '</p>',
'[left]' => '<p style="text-align:left;">','[/left]' => '</p>',
'[right]' => '<p style="text-align:right;">','[/right]' => '</p>',
'[center]' => '<p style="text-align:center;">','[/center]' => '</p>',
'[justify]' => '<p style="text-align:justify;">','[/justify]' => '</p>',
'[bold]' => '<span style="font-weight:bold;">','[/bold]' => '</span>',
'[italic]' => '<span style="font-weight:bold;">','[/italic]' => '</span>',
'[underline]' => '<span style="text-decoration:underline;">','[/underline]' => '</span>',
'[b]' => '<span style="font-weight:bold;">','[/b]' => '</span>',
'[i]' => '<span style="font-weight:bold;">','[/i]' => '</span>',
'[u]' => '<span style="text-decoration:underline;">','[/u]' => '</span>',
'[break]' => '<br>',
'[br]' => '<br>',
'[newline]' => '<br>',
'[nl]' => '<br>',
'[unordered_list]' => '<ul>','[/unordered_list]' => '</ul>',
'[list]' => '<ul>','[/list]' => '</ul>',
'[ul]' => '<ul>','[/ul]' => '</ul>',
'[ordered_list]' => '<ol>','[/ordered_list]' => '</ol>',
'[ol]' => '<ol>','[/ol]' => '</ol>',
'[list_item]' => '<li>','[/list_item]' => '</li>',
'[li]' => '<li>','[/li]' => '</li>',
'[*]' => '<li>','[/*]' => '</li>',
'[code]' => '<code>','[/code]' => '</code>',
'[preformatted]' => '<pre>','[/preformatted]' => '</pre>',
'[pre]' => '<pre>','[/pre]' => '</pre>',
);
$bbtext = str_ireplace(array_keys($bbtags), array_values($bbtags), $bbtext);
$bbextended = array(
"/\[url](.*?)\[\/url]/i" => "<a href=\"http://$1\" title=\"$1\">$1</a>",
"/\[url=(.*?)\](.*?)\[\/url\]/i" => "<a href=\"$1\" title=\"$1\">$2</a>",
"/\[email=(.*?)\](.*?)\[\/email\]/i" => "<a href=\"mailto:$1\">$2</a>",
"/\[mail=(.*?)\](.*?)\[\/mail\]/i" => "<a href=\"mailto:$1\">$2</a>",
"/\[img\]([^[]*)\[\/img\]/i" => "<img src=\"$1\" alt=\" \" />",
"/\[image\]([^[]*)\[\/image\]/i" => "<img src=\"$1\" alt=\" \" />",
"/\[image_left\]([^[]*)\[\/image_left\]/i" => "<img src=\"$1\" alt=\" \" class=\"img_left\" />",
"/\[image_right\]([^[]*)\[\/image_right\]/i" => "<img src=\"$1\" alt=\" \" class=\"img_right\" />",
);
foreach($bbextended as $match=>$replacement){
$bbtext = preg_replace($match, $replacement, $bbtext);
}
return $bbtext;
}
//=====================================================================//
// FUNCTION: bbcode_to_html //
//========================= END OF FUNCTION ===========================//
And used it as the exemple above:
$bbtext = '[b]Text[/b]';
$html = bbcode_to_html($bbtext);
echo $html;
API has two methods to work with the HTML code.
Get HTML content
$("#editor").htmlcode();
Set HTML content
$("#editor").htmlcode(htmlcode);
http://www.wysibb.com/docs/p9.html
I hope this helps you and others looking for answer
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.