33 lines
No EOL
1 KiB
PHP
Executable file
33 lines
No EOL
1 KiB
PHP
Executable file
<?php
|
|
function markdown($text) {
|
|
$search = array (
|
|
'~(?:\s|^)(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i',
|
|
'~(?:@)([^\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 (
|
|
'<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;
|
|
}
|
|
?>
|