gtal3x Posted October 31, 2007 Share Posted October 31, 2007 Hello yestarday someone gave me a code that converts bbcode to html wich works perfectly, all i wont now is to add to this code an array variable for smilies. I have got the smilies array, but i dont know how to add this variable to the first code... Thats the bbcode to html allone: function bb2html($text) { $bbcode = array("<", ">", "[list]", "[*]", "[/list]", "[img=", "]", "[b]", "[/b]", "[u]", "[/u]", "[i]", "[/i]", '[color="', "[/color]", "[size=\"", "[/size]", '[url]', "[/url]", "[mail=\"", "[/mail]", "[quote]", "[/quote]", '\\"]'); $htmlcode = array("<", ">", "<ul>", "<li>", "</ul>", "<img src=\"", "\">", "<b>", "</b>", "<u>", "</u>", "<i>", "</i>", "<span style=\"color:", "</span>", "<span style=\"font-size:", "</span>", '<a href="', "</a>", "<a href=\"mailto:", "</a>", "<table width=100% bgcolor=lightgray><tr><td bgcolor=white>", "</td></tr></table>", '">'); $newtext = str_replace($bbcode, $htmlcode, $text); //$newtext = nl2br($newtext);//second pass return $newtext; } And here is the array variable for smilies: $smilies = array( "" => "smile1.gif", "" => "wink.gif", "" => "grin.gif", "" => "tongue.gif", "" => "sad.gif", ":'(" => "cry.gif", ":|" => "noexpression.gif", ":-/" => "confused.gif", ":-O" => "ohmy.gif", "" => "cool1.gif", "O:-" => "angel.gif", "" => "sleep.gif", ":grrr:" => "angry.gif", ":smile:" => "smile2.gif", "" => "laugh.gif", ":cool:" => "cool2.gif", ":fun:" => "fun.gif", ":thumbsup:" => "thumbsup.gif", ":thumbsdown:" => "thumbsdown.gif", ":blush:" => "blush.gif", ); Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/75559-solved-bb-code-with-smilies-simple-question/ Share on other sites More sharing options...
MadTechie Posted October 31, 2007 Share Posted October 31, 2007 Just create another function ie <?php function smillies($text) { $smilies = array( "" => "smile1.gif", "" => "wink.gif", "" => "grin.gif", "" => "tongue.gif", "" => "sad.gif", ":'(" => "cry.gif", ":|" => "noexpression.gif", ":-/" => "confused.gif", ":-O" => "ohmy.gif", "" => "cool1.gif", "O:-" => "angel.gif", "" => "sleep.gif", ":grrr:" => "angry.gif", ":smile:" => "smile2.gif", "" => "laugh.gif", ":cool:" => "cool2.gif", ":fun:" => "fun.gif", ":thumbsup:" => "thumbsup.gif", ":thumbsdown:" => "thumbsdown.gif", ":blush:" => "blush.gif" ); $smiliesK = array_keys($smilies); $newtext = str_replace($smiliesK, "<img src='$smilies'>", $text); //may need to add image path return $newtext; } ?> **untested use just like the bbcode Quote Link to comment https://forums.phpfreaks.com/topic/75559-solved-bb-code-with-smilies-simple-question/#findComment-382273 Share on other sites More sharing options...
gtal3x Posted October 31, 2007 Author Share Posted October 31, 2007 any solution to make this look like that: function bb2html($text) { $bbcode = array("<", ">", "[list]", "[*]", "[/list]", "[img=", "]", "[b]", "[/b]", "[u]", "[/u]", "[i]", "[/i]", '[color="', "[/color]", "[size=\"", "[/size]", '[url]', "[/url]", "[mail=\"", "[/mail]", "[quote]", "[/quote]", '$smilie[]' // <------------- I know this variable is wrong just dont know how to do it '\\"]'); $htmlcode = array("<", ">", "<ul>", "<li>", "</ul>", "<img src=\"", "\">", "<b>", "</b>", "<u>", "</u>", "<i>", "</i>", "<span style=\"color:", "</span>", "<span style=\"font-size:", "</span>", '<a href="', "</a>", "<a href=\"mailto:", "</a>", "<table width=100% bgcolor=lightgray><tr><td bgcolor=white>", "</td></tr></table>", "[img=$smile[]]" // <----------- Into this '">'); $newtext = str_replace($bbcode, $htmlcode, $text); //$newtext = nl2br($newtext);//second pass return $newtext; } Quote Link to comment https://forums.phpfreaks.com/topic/75559-solved-bb-code-with-smilies-simple-question/#findComment-382281 Share on other sites More sharing options...
gtal3x Posted October 31, 2007 Author Share Posted October 31, 2007 Ok i have this code now but i get an error for some reason... am really not good with arrays so just dont know how to make it work... $body = ""; $smilies = array( "" => "smile1.gif", "" => "wink.gif", "" => "grin.gif", "" => "tongue.gif", "" => "sad.gif", ":'(" => "cry.gif", ":|" => "noexpression.gif", ":-/" => "confused.gif", ":-O" => "ohmy.gif", "" => "cool1.gif", "O:-" => "angel.gif", "" => "sleep.gif", ":grrr:" => "angry.gif", ":smile:" => "smile2.gif", "" => "laugh.gif", ":cool:" => "cool2.gif", ":fun:" => "fun.gif", ":thumbsup:" => "thumbsup.gif", ":thumbsdown:" => "thumbsdown.gif", ":blush:" => "blush.gif", ); function bb2html($text) { $bbcode = array("<", ">", "[list]", "[*]", "[/list]", "[img=", "]", "[b]", "[/b]", "[u]", "[/u]", "[i]", "[/i]", '[color="', "[/color]", "[size=\"", "[/size]", '[url]', "[/url]", "[mail=\"", "[/mail]", "[quote]", "[/quote]", '\\"]'); $htmlcode = array("<", ">", "<ul>", "<li>", "</ul>", "<img src=\"", "\">", "<b>", "</b>", "<u>", "</u>", "<i>", "</i>", "<span style=\"color:", "</span>", "<span style=\"font-size:", "</span>", '<a href="', "</a>", "<a href=\"mailto:", "</a>", "<table width=100% bgcolor=lightgray><tr><td bgcolor=white>", "</td></tr></table>", '">'); $newtext = str_replace($bbcode, $htmlcode, $text); //$newtext = nl2br($newtext);//second pass $smiliesK = array_keys($smilies); $newtext = str_replace($smiliesK, "<img src='images/smilies/$smilies'>", $text); return $newtext; } echo bb2html($body); The error that am getting is: Warning: array_keys() [function.array-keys]: The first argument should be an array in C:\........... Quote Link to comment https://forums.phpfreaks.com/topic/75559-solved-bb-code-with-smilies-simple-question/#findComment-382332 Share on other sites More sharing options...
MadTechie Posted November 1, 2007 Share Posted November 1, 2007 if you are using the array in the function then you must put the array in the function... $body = ""; function bb2html($text) { $bbcode = array("<", ">", "[list]", "[*]", "[/list]", "[img=", "]", "[b]", "[/b]", "[u]", "[/u]", "[i]", "[/i]", '[color="', "[/color]", "[size=\"", "[/size]", '[url]', "[/url]", "[mail=\"", "[/mail]", "[quote]", "[/quote]", '\\"]'); $htmlcode = array("<", ">", "<ul>", "<li>", "</ul>", "<img src=\"", "\">", "<b>", "</b>", "<u>", "</u>", "<i>", "</i>", "<span style=\"color:", "</span>", "<span style=\"font-size:", "</span>", '<a href="', "</a>", "<a href=\"mailto:", "</a>", "<table width=100% bgcolor=lightgray><tr><td bgcolor=white>", "</td></tr></table>", '">'); $newtext = str_replace($bbcode, $htmlcode, $text); //$newtext = nl2br($newtext);//second pass $smilies = array( "" => "smile1.gif", "" => "wink.gif", "" => "grin.gif", "" => "tongue.gif", "" => "sad.gif", ":'(" => "cry.gif", ":|" => "noexpression.gif", ":-/" => "confused.gif", ":-O" => "ohmy.gif", "" => "cool1.gif", "O:-" => "angel.gif", "" => "sleep.gif", ":grrr:" => "angry.gif", ":smile:" => "smile2.gif", "" => "laugh.gif", ":cool:" => "cool2.gif", ":fun:" => "fun.gif", ":thumbsup:" => "thumbsup.gif", ":thumbsdown:" => "thumbsdown.gif", ":blush:" => "blush.gif", ); but personally i would use my first suggestion! $smiliesK = array_keys($smilies); $newtext = str_replace($smiliesK, "<img src='images/smilies/$smilies'>", $text); return $newtext; } echo bb2html($body); Quote Link to comment https://forums.phpfreaks.com/topic/75559-solved-bb-code-with-smilies-simple-question/#findComment-382443 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.