0

I made little javascript bbcode editor on my website. How to display that code from mysql? Or how to save in mysql as html that code?

3
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by diafol
1
<?php
function parseBBCode($text)
{
    $ALLOWABLE_TAGS = array("b", "i", "u"); //Add tags here
    static $PATTERNS = array();
    static $REPLACEMENTS = array();
    if (count($PATTERNS) == 0) {
        foreach ($ALLOWABLE_TAGS as $tag) {
            $PATTERNS[] = "/[$tag]/i";
            $PATTERNS[] = "/[\/$tag]/i";
            $REPLACEMENTS[] = "<$tag>";
            $REPLACEMENTS[] = "</$tag>";
        }
    }
    $result = str_replace(array(">", "<", "\"", "'"),
                       array("&gt;", "&lt;", "&quot;", "&#039;"),
                       $text);
    $result = preg_replace($PATTERNS, $REPLACEMENTS, $result);
    return $result;
}
?>

Untested, but should work

0

Looks good. How about having allowable bbcode tags set to different html tags? b -> strong, i -> em. That should make it more xhtml-compliant.

0

Thanks, but i have option for code like on this site. How to display php code on website i tried

<pre>

but it doesn't work.

0

This site uses '<pre class="code">' and ordered lists ('<ol><li>..</li>....</ol>') on every line to ensure line numbers.

0

How to transform every line to <li>?

Edited by web3: n/a

0

I assume it's:
Search for newline and replace with '</li><li>'. Place a '<li>' at the start and a '</li>' at the end.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.