Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 979891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:17:25+00:00 2026-05-16T04:17:25+00:00

With the code below some smilies won’t work (the text isn’t replaced by a

  • 0

With the code below some smilies won’t work (the text isn’t replaced by a smiley). When I change the order of the $smileys array, the broken smileys work but others don’t.

So I know the order of the $smileys array determines the replacement of the smilies, but I don’t know why.

Can anybody help me to let all the smileys work properly? Thanks

public $smileys = array(
    'tongetje.gif'  => array(':p',':P'),
    'cool.gif'  => array(':8'),
    'dansen.gif'=> array('(dance)'),
    'mondje_dicht.gif' => array(':|'),
    'muur_hoofd.gif'    => array('|:('),
    'huilen.gif'    => array('(h)'),
    'loser.gif' => array('(:)'),
    'lachje.gif' => array(':)',':-)'),
    'wink.gif'  => array(';)'),
    'lach.gif'  => array(':d',':-D'),
    'lollol.gif'    => array(':#'),
    'bloos.gif' => array('(b)'),
    'stom.gif'  => array(':s'),
    'doei.gif'  => array('(d)'),
    'engeltje.gif' => array('O-)'),
    'boze_smiley.gif' => array(':('),
    '1april.gif' => array(':1)'),
    'koning.gif' => array('(koning)'),
    'offtopic.gif' => array('*-*'),
    'opgeven_verlegen.gif' => array('O+'),
     'piraat.gif' => array(':F'),
    'politie.gif' => array('(p)'),
    'reggae.gif' => array('(r)'),
    'jammie.gif' => array(':9'),
    'schamen.gif' => array(':-8'),
    'verliefd.gif' => array(':00'),
    'middelvinger.gif' => array(':--')
);      

private function ubb_smileys($string) {
    $counter = 1;
    foreach($this->smileys as $imagename => $imagetags) {
        if(is_numeric($this->smilies_enable)) {
            if($counter <= $this->smilies_enable) {
                foreach($imagetags as $int => $tag) {
                    $tag = str_replace("\\", "", $tag);
                    $src = UBB_SMILEYS_PATH.$imagename;
                    $image = UBB_SMILEYS_STRING;
                    $image = str_replace('${TAG}', $tag, $image);
                    $image = str_replace('${SRC}', $src, $image);
                    $string = str_replace($tag, $image, $string);

                }
            }
        } else {
            foreach($imagetags as $int => $tag) {
                $tag = str_replace("\\", "", $tag);
                $src = UBB_SMILEYS_PATH.$imagename;
                $image = UBB_SMILEYS_STRING;
                $image = str_replace('${TAG}', $tag, $image);
                $image = str_replace('${SRC}', $src, $image);
                $string = str_replace($tag, $image, $string);

            }
        }
        $counter++;
    }
    return $string;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:17:26+00:00Added an answer on May 16, 2026 at 4:17 am

    I expect it is because some smileys are subsets of others. For example ‘:)’ is a subset of ‘(:)’. So if it came before ‘:)’, ‘(:)’ would never be found.

    Include the most complicated ones first, and then any smiley that is a subset of another smiley must come later.

    This explains why the ordering is affecting your results.

    That said — I can’t find a specific example of the ordering in the order you posted above (although I may not have looked for long enough). With the above-posted order, which smileys are not working for you?

    EDIT:

    I tested with the below. Works fine for me. What are you using as a test string?

    define('UBB_SMILEYS_PATH', '/images/');
    define('UBB_SMILEYS_STRING', '<img src="${SRC}" alt="${TAG}" />');
    
    class UBB {
        public $smileys_enable;
    
        public function __construct() {
            $this->smilies_enable = 100;
        }
    
        public $smileys = array(
            'tongetje.gif'  => array(':p',':P'),
            'cool.gif'  => array(':8'),
            'dansen.gif'=> array('(dance)'),
            'mondje_dicht.gif' => array(':|'),
            'muur_hoofd.gif'    => array('|:('),
            'huilen.gif'    => array('(h)'),
            'loser.gif' => array('(:)'),
            'lachje.gif' => array(':)',':-)'),
            'wink.gif'  => array(';)'),
            'lach.gif'  => array(':d',':-D'),
            'lollol.gif'    => array(':#'),
            'bloos.gif' => array('(b)'),
            'stom.gif'  => array(':s'),
            'doei.gif'  => array('(d)'),
            'engeltje.gif' => array('O-)'),
            'boze_smiley.gif' => array(':('),
            '1april.gif' => array(':1)'),
            'koning.gif' => array('(koning)'),
            'offtopic.gif' => array('*-*'),
            'opgeven_verlegen.gif' => array('O+'),
             'piraat.gif' => array(':F'),
            'politie.gif' => array('(p)'),
            'reggae.gif' => array('(r)'),
            'jammie.gif' => array(':9'),
            'schamen.gif' => array(':-8'),
            'verliefd.gif' => array(':00'),
            'middelvinger.gif' => array(':--')
        );      
    
        private function ubb_smileys($string) {
            $counter = 1;
            foreach($this->smileys as $imagename => $imagetags) {
                if(is_numeric($this->smilies_enable)) {
                    if($counter <= $this->smilies_enable) {
                        foreach($imagetags as $int => $tag) {
                            $tag = str_replace("\\", "", $tag);
                            $src = UBB_SMILEYS_PATH.$imagename;
                            $image = UBB_SMILEYS_STRING;
                            $image = str_replace('${TAG}', $tag, $image);
                            $image = str_replace('${SRC}', $src, $image);
                            $string = str_replace($tag, $image, $string);
    
                        }
                    }
                } else {
                    foreach($imagetags as $int => $tag) {
                        $tag = str_replace("\\", "", $tag);
                        $src = UBB_SMILEYS_PATH.$imagename;
                        $image = UBB_SMILEYS_STRING;
                        $image = str_replace('${TAG}', $tag, $image);
                        $image = str_replace('${SRC}', $src, $image);
                        $string = str_replace($tag, $image, $string);
    
                    }
                }
                $counter++;
            }
            return $string;
        }
        public function parse_smileys($str) {
            return $this->ubb_smileys($str);
        }
    }
    
    $ubb = new UBB();
    
    $myStr = 'xxx :-) :s lalala (d) :( Some text';
    
    echo($ubb->parse_smileys($myStr));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.