Jump to content

Recommended Posts

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

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

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?"

  • Like 1
Link to comment
https://forums.phpfreaks.com/topic/297170-help-with-php-array/#findComment-1515557
Share on other sites

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..

 

CLqmE7t.png

 

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

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 by Ch0cu3r
Link to comment
https://forums.phpfreaks.com/topic/297170-help-with-php-array/#findComment-1515566
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.