All pastes #117338 Raw Edit

Miscellany

public php v1 · immutable
·published 2006-08-05 22:08 UTC
rendered paste body
function bbcode($string){	$string = nl2br(htmlspecialchars($string));	$patterns = array(                                    '`\[b\](.+?)\[/b\]`is',                                    '`\[i\](.+?)\[/i\]`is',                                    '`\[u\](.+?)\[/u\]`is',                                    '`\[strike\](.+?)\[/strike\]`is',                                    '`\[color=#([0-9]{6})\](.+?)\[/color\]`is',                                    '`\[email\](.+?)\[/email\]`is',                                    '`\[img\](.+?)\[/img\]`is',                                    '`\[url=([a-z0-9]+://)([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\](.*?)\[/url\]`si',                                    '`\[url\]([a-z0-9]+?://){1}([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)\[/url\]`si',                                    '`\[url\]((www|ftp)\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\[/url\]`si',                                    '`\[quote\](.+?)\[/quote\]`is',                                    '`\[indent](.+?)\[/indent\]`is',                                    '`\[size=([1-6]+)\](.+?)\[/size\]`is'                                                                );	$replaces =  array(                                    '<strong>\\1</strong>',                                    '<em>\\1</em>',                                    '<span style="border-bottom: 1px dotted">\\1</span>',                                    '<del>\\1</del>',                                    '<span style="color:#\1;">\2</span>',                                    '<a href="mailto:\1">\1</a>',                                    '<img src="\1" alt="" style="border:0px;" />',                                    '<a href="\1\2">\6</a>',                                    '<a href="\1\2">\1\2</a>',                                    '<a href="http://\1">\1</a>',                                    '<strong>Quote:</strong></p><div class="quote"><em>\1</em></div><p>',                                    '<pre>\\1</pre>',                                    '</p><h\1>\2</h\1><p>'                                                                                                            );$string = preg_replace($patterns, $replaces , $string);return $string;}