Jump to content

[SOLVED] BBcode - adding smilies


MasterACE14

Recommended Posts

I have this BBcode:

<?php
// bbcode
function bbcode($string)
{
    // All the default bbcode arrays.
    $bbcode = array(
        //Text Apperence
        '#\[b\](.*?)\[/b\]#si' => '<b>\\1</b>',
        '#\[i\](.*?)\[/i\]#si' => '<i>\\1</i>',
        '#\[u\](.*?)\[/u\]#si' => '<u>\\1</u>',
       // '#\[s\](.*?)\[/s\]#si' => '<strike>\\1</strike>',
        //Font Color
        '#\[color=(.*?)\](.*?)\[/color\]#si' => '<font color="\\1">\\2</font>',
        //Text Effects
       // '#\[bl\](.*?)\[/bl\]#si' => '<blink>\\1</blink>',
       // '#\[marquee\](.*?)\[/marquee\]#si' => '<marquee>\\1</marquee>',
        //Other
       // '#\[code\](.*?)\[/ code]#si' => '<div class="bbcode_code_title">CODE:</div><div class="bbcode_code_code">\\1<div>',
        '#\[url=(.*?)\](.*?)\[/url]#si' => '<a href="\\1" target="_blank">\\2</a>',
       // '#\[quote\](.*?)\[/quote\]#si' => '<div class="bbcode_quote_title">CODE:</div><div class="bbcode_quote_quote">\\1<div>',
       // '#\[img\](.*?)\[/img\]#si' => '<img src="\\1">',
        '#\[email\](.*?)\[/email\]#si' => '<a href="mailto:\\1">\\1</a>'
    );
    $output = preg_replace(array_keys($bbcode), array_values($bbcode), $string);
   return nl2br($output);
}

 

and I want to add smilies.

 

like...

: )

would be replaced with icon_e_smile.gif

 

I've tried a few things with no luck.

 

Any help is greatly appreciated.

 

Regards ACE

Link to comment
https://forums.phpfreaks.com/topic/133628-solved-bbcode-adding-smilies/
Share on other sites

str_replace() is fine for this.

 

<?php

$what = array(
	"",
	"",
	""
	);
$with = array(
	"<img src='smile.gif' alt='Smile' />",
	"<img src='grin.gif' alt='Grin' />",
	"<img src='tongue.gif' alt='Tongue' />"
	);
$content = str_replace($what, $with, $content);
?>

 

Or you could set it up how you have, using array_keys() and array_values().

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.