kuimera Posted July 4, 2015 Share Posted July 4, 2015 Hi guys, I have a php plugin that I use for smilies, it uses array to pinpoint what code is used for each smile image for example: $people = array ( ':)' => 'smile.png', ':laughing:' => 'laughing.png', ':blush:' => 'blush.png', ':d' => 'smiley.png', now, I'm having trouble adding two types of code for each image without duplicating the smile image in the plugin, I have tried to use: ':d',':D' => smiley.png, but I had no success because it seem to work but it mess up my plugin... Any ideas? Can someone help me on this please? Quote Link to comment Share on other sites More sharing options...
requinix Posted July 4, 2015 Share Posted July 4, 2015 (edited) So you're trying to add ? Copy the line for and change it to a capital D. Edited July 4, 2015 by requinix Quote Link to comment Share on other sites More sharing options...
kuimera Posted July 4, 2015 Author Share Posted July 4, 2015 (edited) So you're trying to add ? Copy the line for and change it to a capital D. Thank you for the quick reply req, I want both and for the same image without duplicating the image or line for that mater.. Edited July 4, 2015 by kuimera Quote Link to comment Share on other sites More sharing options...
denno020 Posted July 4, 2015 Share Posted July 4, 2015 You're going to have to have 2 array entries for each of your shortcuts, but if you don't want to double up the name for the smiley, you could use a constant define("SMILIES__SMILE", "smiley.png"); $people = array( ":d" => SMILIES__SMILE, ":D" => SMILIES__SMILE ); That way, you still only have 1 place where you define the actual name for the smiley image. Denno Quote Link to comment Share on other sites More sharing options...
Barand Posted July 4, 2015 Share Posted July 4, 2015 Alternatively $images = array ( 1 => 'smile.png', 2 => 'laughing.png', 3 => 'blush.png', 4 => 'smiley.png' ); $people = array ( ':)' => 1, ':laughing:' => 2, ':blush:' => 3, ':d' => 4, ':D' => 4 ); But the question is "why are you imposing an artificial constraint that makes life difficult for you when this: $people = array ( ':d' => 'smiley.png', ':D' => 'smiley.png' ); is a perfectly legitimate array?" 1 Quote Link to comment Share on other sites More sharing options...
kuimera Posted July 4, 2015 Author Share Posted July 4, 2015 Alternatively $images = array ( 1 => 'smile.png', 2 => 'laughing.png', 3 => 'blush.png', 4 => 'smiley.png' ); $people = array ( ':)' => 1, ':laughing:' => 2, ':blush:' => 3, ':d' => 4, ':D' => 4 ); But the question is "why are you imposing an artificial constraint that makes life difficult for you when this: $people = array ( ':d' => 'smiley.png', ':D' => 'smiley.png' ); is a perfectly legitimate array?" Forget to mention that there is a panel that popup to pick the smilies, so having two lines would duplicate the image on that panel.. Either way, thank you for the reply Denno and Barand, I'm going to try your solution. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted July 4, 2015 Share Posted July 4, 2015 (edited) Why not just make the replacement of the smiley codes be case-insensitve? function imageTag($value) { return '<img src="' . $value . '" />'; } $message = str_ireplace( array_keys($people) , array_map('imageTag', array_values($people)) , $message); Now you dont need to define : d or : D as smiley.gif Alternatively use array_unique when displaying your simileys EDIT: Damn stupid form keeps rendering the simely codes, even when wrapped in in nobbc tag Edited July 4, 2015 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
kuimera Posted July 4, 2015 Author Share Posted July 4, 2015 Thanks a lot Ch0cu3r! Very smart, that didn't occur to me.. Worked like a charm Quote Link to comment 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.