$search = "/[BOLD]/";
$replace = "<b>";
preg_replace($search, $replace, $str);
function bracket2html($str)
{
$search[0] = "/\[CODE\](.+)\[\/CODE\]/"; $replace[0] = "<br /><div style=\"width: 95%; padding: 0px 5px 10px 5px; background-color: #999999; border: 1px solid #404040;\"><font style=\"font-family: Courier new;\">\\1</font></div><br />";
//some more $search and $replace arrays
$str = preg_replace($search, $replace, $str);
$str = str_replace("\n", "<br />", $str);
return $str;
}
$search[1] = "/\[SNIP\](.+)\[\/SNIP\]/";
$replace[1] = "<font style=\"font-family: courier new;\">\\1</font>";
$search[2] = "/\[B\](.+)\[\/B\]/";
$replace[2] = "<b>\\1</b>";
$search[3] = "/\[BOLD\](.+)\[\/BOLD\]/";
$replace[3] = "<b>\\1</b>";
$search[4] = "/\[U\](.+)\[\/U\]/";
$replace[4] = "<u>\\1</u>";
$search[5] = "/\[UNDERLINE\](.+)\[\/UNDERLINE\]/";
$replace[5] = "<u>\\1</u>";
$search[6] = "/\[LINK=\"(.+)\"\](.+)\[\/LINK\]/";
$replace[6] = "<a href=\"\\1\">\\2</a>";
$search[7] = "/\[IMG=\"(.+)\"\]/";
$replace[7] = "<img src=\"images/\\1\" />";
Ah the beauty of regular expressions!! Check your expressions using the Reg Ex Coach: http://weitz.de/regex-coach/CHiLLaXen said:YES! I found out why it wasn't working. instead of using (.+) I have to use (.*?)
a1ehouse said:Ah the beauty of regular expressions!! Check your expressions using the Reg Ex Coach: http://weitz.de/regex-coach/
function bbCodeconverter($text){
$search[0] = "/\[[bB]\](.*?)\[\/[bB]*\]/";
$replace[0] = "<b>\\1</b>";
$search[1] = "/\[img\](.*?)\[\/img]/";
$replace[1] = "<img src=\"\\1\">";
$text = preg_replace($search,$replace,$text);
$text = str_replace("\n","<br>",$text);
return $text;
}
<?php
$keyword='iMg';
$string='img';
$string = preg_replace('!('.$keyword.')!i','<span style="color:red">$1</span>',$string);
echo $string;
?>
<?php
echo sql_regcase("img");
// [Ii][Mm][Gg]
?>
<b> is depreciated and may be removed from the HTML spec sometime in the futureGlaanieboy said:Thank you both
@bunny: Why should I use <strong>? <b> does the same for me, and it is less typing
$search[] = "/\[url\](.*?)\[\/url\]/i";
$replace[] = "<a href=\"\\1\">\\1</a>";
function strLongURI($uri){
$uri_len = strlen($uri);
if ($uri_len >= 15){
$first_part = substr($uri,0,7);
$second_part = substr($uri,-7);
$str_uri = $first_part."..".$second_part;
}else{
$str_uri = $uri;
}
return $str_uri;
}