• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[ZNOTE AAC] URL tag on Forums

kito2

www.masteria.net
Joined
Mar 9, 2009
Messages
3,766
Solutions
1
Reaction score
225
Location
Chile, Santiago
Hey,

Does anyone knows how to add to the current tags the option to do:

Code:
[url=https://mtibia.online/intro]TEXT[/url]

The current tags are like this:

PHP:
$tags = array(
        '[center]{$1}[/center]' => '<center>$1</center>',
        '[b]{$1}[/b]' => '<b>$1</b>',
        '[img]{$1}[/img]'    => '<a href="$1" target="_BLANK"><img src="$1" alt="image" style="width: 100%"></a>',
        '[link]{$1}[/link]'    => '<a href="$1">$1</a>',
        '[link={$1}]{$2}[/link]'   => '<a href="$1" target="_BLANK">$2</a>',
        '[color={$1}]{$2}[/color]' => '<font color="$1">$2</font>',
        '[*]{$1}[/*]' => '<li>$1</li>',
       
    );

Thanks in advice!
 
Solution
Remove target="_blank" if you don't want it to open in a new tab
PHP:
'[url={$1}]{$2}[/url]' => '<a href="$1" target="_BLANK">$2</a>',


Added this if-statement to append http:// or https:// in the href if the user doesn't do it, if not the url gets prefixed with the server url.
PHP:
if (strpos($string, "<a href=") !== false) {
    if (strpos($string, "http") === false) {
        $string = substr_replace($string, "//", 9, 0);
    }
}


Full function
PHP:
function TransformToBBCode($string) {
    $tags = array(
        '[center]{$1}[/center]' => '<center>$1</center>',
        '[b]{$1}[/b]' => '<b>$1</b>',
        '[img]{$1}[/img]'    => '<a href="$1" target="_BLANK"><img src="$1" alt="image" style="width: 100%"></a>',
        '[link]{$1}[/link]'    => '<a...
Remove target="_blank" if you don't want it to open in a new tab
PHP:
'[url={$1}]{$2}[/url]' => '<a href="$1" target="_BLANK">$2</a>',


Added this if-statement to append http:// or https:// in the href if the user doesn't do it, if not the url gets prefixed with the server url.
PHP:
if (strpos($string, "<a href=") !== false) {
    if (strpos($string, "http") === false) {
        $string = substr_replace($string, "//", 9, 0);
    }
}


Full function
PHP:
function TransformToBBCode($string) {
    $tags = array(
        '[center]{$1}[/center]' => '<center>$1</center>',
        '[b]{$1}[/b]' => '<b>$1</b>',
        '[img]{$1}[/img]'    => '<a href="$1" target="_BLANK"><img src="$1" alt="image" style="width: 100%"></a>',
        '[link]{$1}[/link]'    => '<a href="$1">$1</a>',
        '[link={$1}]{$2}[/link]'   => '<a href="$1" target="_BLANK">$2</a>',
        '[url={$1}]{$2}[/url]'   => '<a href="$1" target="_BLANK">$2</a>',
        '[color={$1}]{$2}[/color]' => '<font color="$1">$2</font>',
        '[*]{$1}[/*]' => '<li>$1</li>',
        '[youtube]{$1}[/youtube]' => '<div class="youtube"><div class="aspectratio"><iframe src="//www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe></div></div>',
    );
    foreach ($tags as $tag => $value) {
        $code = preg_replace('/placeholder([0-9]+)/', '(.*?)', preg_quote(preg_replace('/\{\$([0-9]+)\}/', 'placeholder$1', $tag), '/'));
        $string = preg_replace('/'.$code.'/i', $value, $string);
        if (strpos($string, "<a href=") !== false) {
            if (strpos($string, "http") === false) {
                $string = substr_replace($string, "//", 9, 0);
            }
        }
    }
    return $string;
}
 
Last edited:
Solution
Back
Top