# Question about order of smilies

**URL:** <https://boards.straightdope.com/t/question-about-order-of-smilies/167823>\
**Category:** About This Message Board\
**Created:** [April 10, 2003, 5:25pm UTC](https://boards.straightdope.com/t/question-about-order-of-smilies/167823 "2003-04-10T17:25:10Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![whatami](https://avatars.discourse-cdn.com/v4/letter/w/85f322/32.png) [@whatami](https://boards.straightdope.com/u/whatami)\
**Post date:** [April 10, 2003, 5:25pm UTC](https://boards.straightdope.com/t/question-about-order-of-smilies/167823/1 "2003-04-10T17:25:10Z")

</div>

After submitting a post today, (no I didn’t preview), I noticed that the smilie I had intended to show, wasn’t there and another was. Like this

> [@](#):
>
> (on the other hand :rolleyes:)

It took my rolleyes and made it into a smiling smilie.

I understand that I had the colon and parentheses there for the smilie, but the rolleyes was in line first.

So, how does the software decide which smilie takes precedence?

😕

---

<div class="post-metadata">

**Author:** ![Q.E.D](https://avatars.discourse-cdn.com/v4/letter/q/51bf81/32.png) [@Q.E.D](https://boards.straightdope.com/u/Q.E.D)\
**Post date:** [April 10, 2003, 5:40pm UTC](https://boards.straightdope.com/t/question-about-order-of-smilies/167823/2 "2003-04-10T17:40:41Z")

</div>

Whichever one the scripts grab first. It’ll be similar to this in PHP:

```php

$message =~ s/:)/ <IMG SRC="$fileurl\/smile.gif">/i;
$message =~ s/:rolleyes:/ <IMG SRC="$fileurl\/rolleyes.gif">/i;
....

```

So, when it hits the first line, it will scan through the text of $message, and when it finds “:)” it will replace it with “\<IMG SRC=http://www.fileurl.com/smile.gif\>”, so that when it gets to the second line, it will see "  
:rolleyes\<IMG SRC=http://www.fileurl.com/smile.gif\>", and the search-and-replace will fail, so no rolleyes smiley will appear.

---

<div class="post-metadata">

**Author:** ![Mangetout](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/mangetout/32/19_2.png) [@Mangetout](https://boards.straightdope.com/u/Mangetout)\
**Post date:** [April 10, 2003, 7:24pm UTC](https://boards.straightdope.com/t/question-about-order-of-smilies/167823/3 "2003-04-10T19:24:55Z")

</div>

A while back, I threw together a very crude message board formatting previewer application; in doing so, I realised that, given the task of converting a finite set of xBoard tags to their HTML equivalent, the only practical way to do it was to take the first tag in the list, then search for it in the message text (replacing where found) until no more instances can be found, then start again with the next tag and so on.  
(the ‘other’ way to do it would be to scan through the text for something that _might be_ a tag, then check if it is one or not - not really practical at all as the code branches off to check every time it finds a [ or a : or whatever)

Anyway, with my code, if there is what appears to be two overlapping tags, it will convert _ **whichever one it looks for first** _, even if this is found **after** a whole bunch of other tags and of course in the case of the example you gave, replacing 🙂 with \<img src=“images/smilies/smile.gif” border=“0” alt=""\> ‘breaks’ the rolleyes smilie tag by stealing the colon off the end, so that by the time it comes round to searching for rolleyes tags in the message text, there aren’t any there (well, no complete ones anyway).

I’ve had my knuckles rapped in the past about making wild speculations about the inner workings of the board, so let me say that it may be that the board software works in a way that is completely different to mine, it behaves as if it does but that may not mean anything.

---

<div class="post-metadata">

**Author:** ![Ethilrist](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ethilrist/32/4604_2.png) [@Ethilrist](https://boards.straightdope.com/u/Ethilrist)\
**Post date:** [April 10, 2003, 7:39pm UTC](https://boards.straightdope.com/t/question-about-order-of-smilies/167823/4 "2003-04-10T19:39:53Z")

</div>

So, always make sure to leave a blank space around your smilies. Or encase them in something other than parentheseses. [:dubious:] \>:rolleyes:\< {:eek:}

---

<div class="post-metadata">

**Author:** ![C\_K\_Dexter\_Haven](https://avatars.discourse-cdn.com/v4/letter/c/b2d939/32.png) [@C\_K\_Dexter\_Haven](https://boards.straightdope.com/u/C_K_Dexter_Haven)\
**Post date:** [April 10, 2003, 9:09pm UTC](https://boards.straightdope.com/t/question-about-order-of-smilies/167823/5 "2003-04-10T21:09:56Z")

</div>

**whatami** , if you ask a moderator nicely, they’ll fix the coding for you, if you tell them specifically where.

---

<div class="post-metadata">

**Author:** ![Achernar](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@Achernar](https://boards.straightdope.com/u/Achernar)\
**Post date:** [April 10, 2003, 9:34pm UTC](https://boards.straightdope.com/t/question-about-order-of-smilies/167823/6 "2003-04-10T21:34:26Z")

</div>

> [@](#):
>
> \*Originally posted by Ethilrist \*  
> So, always make sure to leave a blank space around your smilies. Or encase them in something other than parentheseses.

(There’s another way to do it. :rolleyes:)

---

<div class="post-metadata">

**Author:** ![Profane](https://avatars.discourse-cdn.com/v4/letter/p/e47774/32.png) [@Profane](https://boards.straightdope.com/u/Profane)\
**Post date:** [April 10, 2003, 9:42pm UTC](https://boards.straightdope.com/t/question-about-order-of-smilies/167823/7 "2003-04-10T21:42:15Z")

</div>

)

---

<div class="post-metadata">

**Author:** ![Q.E.D](https://avatars.discourse-cdn.com/v4/letter/q/51bf81/32.png) [@Q.E.D](https://boards.straightdope.com/u/Q.E.D)\
**Post date:** [April 10, 2003, 9:44pm UTC](https://boards.straightdope.com/t/question-about-order-of-smilies/167823/8 "2003-04-10T21:44:04Z")

</div>

Technically, that _would_ be encasing it in something other than parentheses, **Achernar**. 😃

---

<div class="post-metadata">

**Author:** ![Mangetout](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/mangetout/32/19_2.png) [@Mangetout](https://boards.straightdope.com/u/Mangetout)\
**Post date:** [April 10, 2003, 10:22pm UTC](https://boards.straightdope.com/t/question-about-order-of-smilies/167823/9 "2003-04-10T22:22:19Z")

</div>

> [@](#):
>
> \*Originally posted by Ethilrist \*  
> **parentheseses.**

…eseseses 😉

---

<div class="post-metadata">

**Author:** ![whatami](https://avatars.discourse-cdn.com/v4/letter/w/85f322/32.png) [@whatami](https://boards.straightdope.com/u/whatami)\
**Post date:** [April 11, 2003, 2:24pm UTC](https://boards.straightdope.com/t/question-about-order-of-smilies/167823/10 "2003-04-11T14:24:59Z")

</div>

> [@](#):
>
> \*Originally posted by C K Dexter Haven \*  
> \*\ ***whatami** , if you ask a moderator nicely, they’ll fix the coding for you, if you tell them specifically where. \*\*

Thanks **C K** , but it isn’t that big of a deal. After I saw it I just got really curious as to what the order of operations was, to put it into a math term.  
I think I understand now. Thanks **Q.E.D.** and **Mangetout**!

🙂

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [April 11, 2003, 7:41pm UTC](https://boards.straightdope.com/t/question-about-order-of-smilies/167823/11 "2003-04-11T19:41:46Z")

</div>

(But you can use a real parenthesis, too :rolleyes:\*\*\*\*)

---

<div class="post-metadata">

**Author:** ![Achernar](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@Achernar](https://boards.straightdope.com/u/Achernar)\
**Post date:** [April 11, 2003, 7:52pm UTC](https://boards.straightdope.com/t/question-about-order-of-smilies/167823/12 "2003-04-11T19:52:53Z")

</div>

If mine doesn’t count, yours doesn’t either. Your smilie is not surrounded directly by a parenthesis. And you could even call that a blank space, albiet a zero-width one. 😉

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [April 11, 2003, 11:48pm UTC](https://boards.straightdope.com/t/question-about-order-of-smilies/167823/13 "2003-04-11T23:48:54Z")

</div>

> [@](#):
>
> \*Originally posted by Mangetout \*  
> **(the ‘other’ way to do it would be to scan through the text for something that _might be_ a tag, then check if it is one or not - not really practical at all as the code branches off to check every time it finds a [ or a : or whatever)**

Have you ever dealt with finite state automata? I just finished writing a regular expression library, so I’ve been thinking about them a lot lately. Using them, you could treat all the tags and smileys in one pass, and they’re quick unless your implementation totally sucks.

---

<div class="post-metadata">

**Author:** ![Profane](https://avatars.discourse-cdn.com/v4/letter/p/e47774/32.png) [@Profane](https://boards.straightdope.com/u/Profane)\
**Post date:** [April 12, 2003, 3:48am UTC](https://boards.straightdope.com/t/question-about-order-of-smilies/167823/14 "2003-04-12T03:48:10Z")

</div>

\*\*
