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? Link to comment https://forums.phpfreaks.com/topic/297170-help-with-php-array/ Share on other sites More sharing options...
requinix Posted July 4, 2015 Share Posted July 4, 2015 So you're trying to add ? Copy the line for and change it to a capital D. Link to comment https://forums.phpfreaks.com/topic/297170-help-with-php-array/#findComment-1515554 Share on other sites More sharing options...
kuimera Posted July 4, 2015 Author Share Posted July 4, 2015 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.. Link to comment https://forums.phpfreaks.com/topic/297170-help-with-php-array/#findComment-1515555 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 Link to comment https://forums.phpfreaks.com/topic/297170-help-with-php-array/#findComment-1515556 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?" Link to comment https://forums.phpfreaks.com/topic/297170-help-with-php-array/#findComment-1515557 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. Link to comment https://forums.phpfreaks.com/topic/297170-help-with-php-array/#findComment-1515560 Share on other sites More sharing options...
Ch0cu3r Posted July 4, 2015 Share Posted July 4, 2015 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 Link to comment https://forums.phpfreaks.com/topic/297170-help-with-php-array/#findComment-1515566 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 Link to comment https://forums.phpfreaks.com/topic/297170-help-with-php-array/#findComment-1515583 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.