new-bigly-chat/libs/markdown.php

36 lines
1.2 KiB
PHP
Raw Normal View History

2024-12-01 06:20:11 -05:00
<?php
function markdown($text) {
$search = array (
2024-12-07 17:51:05 -05:00
'~(https://[^.]+\.dervland\.net/[^\s<]+)~i',
'~(?:\s|^)(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i',
2024-12-01 06:20:11 -05:00
'~(?:@)([^\s]+)(?:\s|$)~i',
'~(\[b\])(.*?)(\[\/b\])~i',
'~(\[i\])(.*?)(\[\/i\])~i',
'~(\[u\])(.*?)(\[\/u\])~i',
'~(\[ul\])(.*?)(\[\/ul\])~i',
'~(\[li\])(.*?)(\[\/li\])~i',
'~(\[h\])(.*?)(\[\/h\])~i',
'~(\[url=)(.*?)(\])(.*?)(\[\/url\])~i',
'~(\[url\])(.*?)(\[\/url\])~i'
);
$replace = array (
2024-12-07 17:51:05 -05:00
'<a class="link" href="$1" target="_blank"><img src="$1" class="img"></a>',
2024-12-01 06:20:11 -05:00
'<a class="link" href="$0" target="_blank">$0</a>',
'<a class="link" href="/user.php?id=$1" target="_blank">@$1</a>',
'<strong>$2</strong>',
'<em>$2</em>',
'<u>$2</u>',
'<ul>$2</ul>',
'<li>$2</li>',
'<h2>$2</h2>',
'<a class="link" href="$2" target="_blank">$4</a>',
'<a class="link" href="$2" target="_blank">$2</a>'
);
$text = preg_replace($search, $replace, $text);
return $text;
}
2024-12-07 17:51:05 -05:00
?>