Posted: Tue Apr 17, 2007 7:23 pm
That's the only reason I am still posting in it.aaronhall wrote:I think this thread's about due for an updated summary, Kieran
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
That's the only reason I am still posting in it.aaronhall wrote:I think this thread's about due for an updated summary, Kieran
Code: Select all
1 ArrayCode: Select all
echo '<pre>';
print_r($code);Code: Select all
<?php
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',
'`\[flash=([0-9]+),([0-9]+)\](.+?)\[/flash\]`is',
'`\[quote\](.+?)\[/quote\]`is',
'`\[size=([1-6]+)\](.+?)\[/size\]`is'
);
$replaces = array(
'<strong>\\1</strong>',
'<i>\\1</i>',
'<u>\\1</u>',
'<strike>\\1</strike>',
'<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>',
'<object width="\1" height="\2"><param name="movie" value="\3" /><embed src="\3" width="\1" height="\2"></embed></object>',
'<strong>Quote:</strong><div style="margin:0px 10px;padding:5px;background-color:#F7F7F7;border:1px dotted #CCCCCC;width:80%;"><em>\1</em></div>',
'<h\1>\2</h\1>'
);
$string = preg_replace($patterns, $replaces , $string);
return $string;
?>Code: Select all
<?php
function php($string){
$code_count = preg_match_all( '#\[php\](.*?)\[\/php\]#si', $string, $matches);
for( $i = 0; $i < $code_count; $i++ )
{
$replaced = $matches[1][$i];
$replaced = hc( htmlspecialchars2( $replaced ));
return $replaced;
}
}
function htmlspecialchars2( $text )
{
static $patterns, $replaces;
if( !$patterns ){
$patterns = array( '#<#', '#>#', '#&#', '#"#' );
$replaces = array( '<', '>', '&', '"' );
}
return preg_replace( $patterns, $replaces, $text );
}
?>Code: Select all
$code_count = preg_match_all( '#\[php\](.*?)\[\/php\]#si', $string, $matches);
$string = hc( htmlspecialchars2($string));
return $string;
}Code: Select all
<i>test2</i>[php]<?php phpinfo(); ?>[/php] <strong>test</strong>Code: Select all
[i]test2[/i][php]<?php phpinfo(); ?>[/php] [b]test[/b]