function parsetable($width, $bgcolor, $message)
{
    if (strpos($message, '[/tr]') === FALSE && strpos($message, '[/td]') === FALSE) {
        $rows = explode("\n", $message);
        $s = !defined('IN_MOBILE') ? '<table cellspacing="0" class="t_table" ' . ($width == '' ? NULL : 'style="width:' . $width . '"') . ($bgcolor ? ' bgcolor="' . $bgcolor . '">' : '>') : '<table>';
        foreach ($rows as $row) {
            $s .= '<tr><td>' . str_replace(array('\\|', '|', '\\n'), array('&#124;', '</td><td>', "\n"), $row) . '</td></tr>';
        }
        $s .= '</table>';
        return $s;
    } else {
        if (!preg_match("/^\\[tr(?:=([\\(\\)\\s%,#\\w]+))?\\]\\s*\\[td([=\\d,%]+)?\\]/", $message) && !preg_match("/^<tr[^>]*?>\\s*<td[^>]*?>/", $message)) {
            return str_replace('\\"', '"', preg_replace("/\\[tr(?:=([\\(\\)\\s%,#\\w]+))?\\]|\\[td([=\\d,%]+)?\\]|\\[\\/td\\]|\\[\\/tr\\]/", '', $message));
        }
        if (substr($width, -1) == '%') {
            $width = substr($width, 0, -1) <= 98 ? intval($width) . '%' : '98%';
        } else {
            $width = intval($width);
            $width = $width ? $width <= 560 ? $width . 'px' : '98%' : '';
        }
        $patterns = array("/\\[tr(?:=([\\(\\)\\s%,#\\w]+))?\\]\\s*\\[td(?:=(\\d{1,4}%?))?\\]/i", "/\\[\\/td\\]\\s*\\[td(?:=(\\d{1,4}%?))?\\]/i", "/\\[tr(?:=([\\(\\)\\s%,#\\w]+))?\\]\\s*\\[td(?:=(\\d{1,2}),(\\d{1,2})(?:,(\\d{1,4}%?))?)?\\]/i", "/\\[\\/td\\]\\s*\\[td(?:=(\\d{1,2}),(\\d{1,2})(?:,(\\d{1,4}%?))?)?\\]/i");
        $callbacks = array(function ($matches) {
            return parsetrtd($matches[1], '0', '0', $matches[2]);
        }, function ($matches) {
            return parsetrtd('td', '0', '0', $matches[1]);
        }, function ($matches) {
            return parsetrtd($matches[1], $matches[2], $matches[3], $matches[4]);
        }, function ($matches) {
            return parsetrtd('td', $matches[1], $matches[2], $matches[3]);
        });
        foreach ($patterns as $key => $p) {
            $message = preg_replace_callback($p, $callbacks[$key], $message);
        }
        return (!defined('IN_MOBILE') ? '<table cellspacing="0" class="t_table" ' . ($width == '' ? NULL : 'style="width:' . $width . '"') . ($bgcolor ? ' bgcolor="' . $bgcolor . '">' : '>') : '<table>') . str_replace('\\"', '"', preg_replace("/\\[\\/td\\]\\s*\\[\\/tr\\]\\s*/i", '</td></tr>', $message)) . '</table>';
    }
}
function fparsetable($width, $bgcolor, $message)
{
    global $_G;
    $html = '';
    if (strpos($message, '[/tr]') === FALSE && strpos($message, '[/td]') === FALSE) {
        $rows = explode("\n", $message);
        $html = '<table cellspacing="0" class="t_table" ' . ($width == '' ? NULL : 'style="width:' . $width . '"') . ($bgcolor ? ' bgcolor="' . $bgcolor . '">' : '>');
        foreach ($rows as $row) {
            $html .= '<tr><td>' . str_replace(array('\\|', '|', '\\n'), array('&#124;', '</td><td>', "\n"), $row) . '</td></tr>';
        }
        $html .= '</table>';
    } else {
        if (!preg_match("/^\\[tr(?:=([\\(\\)\\s%,#\\w]+))?\\]\\s*\\[td([=\\d,%]+)?\\]/", $message) && !preg_match("/^<tr[^>]*?>\\s*<td[^>]*?>/", $message)) {
            return str_replace('\\"', '"', preg_replace("/\\[tr(?:=([\\(\\)\\s%,#\\w]+))?\\]|\\[td([=\\d,%]+)?\\]|\\[\\/td\\]|\\[\\/tr\\]/", '', $message));
        }
        if (substr($width, -1) == '%') {
            $width = substr($width, 0, -1) <= 98 ? intval($width) . '%' : '98%';
        } else {
            $width = intval($width);
            $width = $width ? $width <= 560 ? $width . 'px' : '98%' : '';
        }
        $message = preg_replace_callback("/\\[tr(?:=([\\(\\)\\s%,#\\w]+))?\\]\\s*\\[td(?:=(\\d{1,4}%?))?\\]/i", function ($matches) {
            return parsetrtd($matches[1], 0, 0, $matches[2]);
        }, $message);
        $message = preg_replace_callback("/\\[\\/td\\]\\s*\\[td(?:=(\\d{1,4}%?))?\\]/i", function ($matches) {
            return parsetrtd('td', 0, 0, $matches[1]);
        }, $message);
        $message = preg_replace_callback("/\\[tr(?:=([\\(\\)\\s%,#\\w]+))?\\]\\s*\\[td(?:=(\\d{1,2}),(\\d{1,2})(?:,(\\d{1,4}%?))?)?\\]/i", function ($matches) {
            return parsetrtd($matches[1], $matches[2], $matches[3], $matches[4]);
        }, $message);
        $message = preg_replace_callback("/\\[\\/td\\]\\s*\\[td(?:=(\\d{1,2}),(\\d{1,2})(?:,(\\d{1,4}%?))?)?\\]/i", function ($matches) {
            return parsetrtd('td', $matches[1], $matches[2], $matches[3]);
        }, $message);
        $html = '<table cellspacing="0" class="t_table" ' . ($width == '' ? NULL : 'style="width:' . $width . '"') . ($bgcolor ? ' bgcolor="' . $bgcolor . '">' : '>') . str_replace('\\"', '"', preg_replace("/\\[\\/td\\]\\s*\\[\\/tr\\]\\s*/i", '</td></tr>', $message)) . '</table>';
    }
    return fcodedisp($html);
}