Jump to content

Array (Duplicate value from other value)


fbemo

Recommended Posts

Hi,

 

I'm trying to create a chatspace inside my web, the code is working just fine but there are slight problems.

 

- When I type :-), it does return a correct value but when I type in >:-), it still will read :-). The result supposedly return an exact value of >:-) not :-). Which this caused the result like this ---> > :D

 

- Same goes when I type :please... it will return the result like this ---> :Please...

 

Question: How to avoid this from reading another value?

 

 

 

$aaa[0] = ":-)";
$aaa[1] = "";
$aaa[2] = ":]";
$aaa[3] = "=)";
$aaa[4] = ":-(";
$aaa[5] = "";
$aaa[6] = ":[";
$aaa[7] = "=(";
.
.
.
$aaa[22] = ">:-(";
$aaa[23] = "";
$aaa[24] = ":-/";
$aaa[25] = ":/";
$aaa[26] = ":-\\";
$aaa[27] = ":\\";
$aaa[28] = ":'(";
$aaa[29] = "";
$aaa[30] = ":*";
$aaa[31] = "";
$aaa[32] = "";
$aaa[33] = "o.O";
$aaa[34] = "O.o";
$aaa[35] = ">-";
$aaa[36] = ">";
$aaa[37] = ">-";
$aaa[38] = ">";
$aaa[39] = ":v";
$aaa[40] = ":3";
$aaa[41] = "8-)";
$aaa[42] = "";
$aaa[43] = "b-)";
$aaa[44] = "b)";
$aaa[45] = "8-|";
$aaa[46] = "8|";
$aaa[47] = "b-|";
$aaa[48] = "b|";
$aaa[49] = "o:-)";
$aaa[50] = "o:)";
$aaa[51] = "3:-)";
$aaa[52] = "3:)";

 

 

Thanks in advance.

 

Link to comment
Share on other sites

Place all of the longer strings before the shorter ones in the array. Or:

<?php
function cmp($a, $b)
{
    return strlen($a)-strlen($b);
}

$array = array(""); //original array
usort($array, "cmp");
$array = array_reverse($array); //new organized array
?>

Link to comment
Share on other sites

Well that's obvious, put >:-( before :-(

 

There's difference in those, for example typing;

 

>:-) will produce  :confused:

 

while if typing

 

:-) will produce  :D

 

 

But my problem is, when people type in >:-) the result print > :D which obviously I don't want it to be this way.

 

 

P.s: The emoticons code can't be changed, so I need an alteration with the coding only, thanks again :)

Link to comment
Share on other sites

Oh, sorry Garethp, i was misunderstood you. You mean, sort the longest strings before the short ones like Stephen said right?

 

Btw, I think there's still problem, here are the strings

 

>:-( not working perfectly by reading the value of :-(

>-:o not working perfectly by reading the value of :-O

O:-) not working perfectly by reading the value of :-)

3:-) not working perfectly by reading the value of :-)

o.O not working perfectly (can't read at all)

 

Which 1 should be the first and last?

 

 

Link to comment
Share on other sites

how are you returning the value ?

 

The value is from user input, it's a chatspace... similar to fb chat. Let say a user type.

You can check it at fbemoticons.com, there are 5 strings not working.

 

>:-( not working perfectly by reading the value of :-(

>-:o not working perfectly by reading the value of :-O

O:-) not working perfectly by reading the value of :-)

3:-) not working perfectly by reading the value of :-)

o.O not working perfectly (can't read at all)

 

Thanks.

Link to comment
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.