Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: ehhh, noob question  (Read 952 times)

0 Members and 1 Guest are viewing this topic.

Xiphirx

wat
ehhh, noob question
« on: October 07, 2008, 02:32:23 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
I just finished writing my Smiley Parser, and it is really strict.

if I type sahaflwhaglsdg:)liahgfkhal

That smiley in the middle will parse

alternatively

if I put a angry smiley like > : (

it puts > (sad smiley)

Code: [Select]
$smilies=array(
    ':)' => "<img src='img/smiley/smile.gif' alt=':)' />",
    '=)' => "<img src='img/smiley/smile.gif' alt='=)' />",
    '=]' => "<img src='img/smiley/smile.gif' alt='=]' />",

    ':(' => "<img src='img/smiley/sad.gif' alt=':(' />",
    '=(' => "<img src='img/smiley/sad.gif' alt='=(' />",
    '=[' => "<img src='img/smiley/sad.gif' alt='=[' />",

   ':S' => "<img src='img/smiley/confused.gif' alt=':S' />",
   '=S' => "<img src='img/smiley/confused.gif' alt='=S' />",

   '8)' => "<img src='img/smiley/cool.gif' alt='8)' />",

   ':,(' => "<img src='img/smiley/cry.gif' alt=':,(' />",

   ':drool:' => "<img src='img/smiley/drool.gif' alt='Drool' />",

   ':happy:' => "<img src='img/smiley/happy.gif' alt='Happy' />",

   '>:/' => "<img src='img/smiley/mad.gif' alt='>:/' />",
   '>=/' => "<img src='img/smiley/mad.gif' alt='>=/' />",
   '>:(' => "<img src='img/smiley/mad.gif' alt='>:(' />",
   '>=(' => "<img src='img/smiley/mad.gif' alt='>=(' />",

   '=_=' => "<img src='img/smiley/sleepy.gif' alt='=_=' />",

   ':O' => "<img src='img/smiley/surprised.gif' alt=':O' />",
   '=O' => "<img src='img/smiley/surprised.gif' alt='=O' />",

   ':P' => "<img src='img/smiley/tongue.gif' alt=':P' />",
   '=P' => "<img src='img/smiley/tongue.gif' alt='=P' />",

    ':D' => "<img src='img/smiley/grin.gif' alt=':D' />",
    '=D' => "<img src='img/smiley/grin.gif' alt='=D' />"
);

...


$entry=str_replace(array_keys($smilies), array_values($smilies), $entry); //Parse any available Smileys



Logged
  • For The Swarm
Re: ehhh, noob question
« Reply #1 on: October 07, 2008, 03:39:56 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3374
when parsing, you need to check for the ones with the most characters before the ones with the least.
In other words, put all the 3 character smilies before the 2 character ones.
Logged
Quote from: Jason
Your community is a bunch of stuck up turds.

Xiphirx

wat
Re: ehhh, noob question
« Reply #2 on: October 07, 2008, 03:57:18 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
New Code
Code: [Select]
$smilies=array(
   '>:)' => "<img src='img/smiley/evil.gif' alt='>:)' />",
   '>=)' => "<img src='img/smiley/evil.gif' alt='>=)' />",
   '>=]' => "<img src='img/smiley/evil.gif' alt='>=]' />",

   '>:/' => "<img src='img/smiley/mad.gif' alt='>:/' />",
   '>=/' => "<img src='img/smiley/mad.gif' alt='>=/' />",
   '>:(' => "<img src='img/smiley/mad.gif' alt='>:(' />",
   '>=(' => "<img src='img/smiley/mad.gif' alt='>=(' />",

   ':,(' => "<img src='img/smiley/cry.gif' alt=':,(' />",
   '=,(' => "<img src='img/smiley/cry.gif' alt='=,(' />",

   'O_O' => "<img src='img/smiley/wha.gif' alt='O_O' />",
   'O_o' => "<img src='img/smiley/wha.gif' alt='O_o' />",

   '>:D' => "<img src='img/smiley/twisted.gif' alt='>:D' />",
   '>=D' => "<img src='img/smiley/twisted.gif' alt='>=D' />",

   '>_>' => "<img src='img/smiley/whatever.gif' alt='>_>' />",
   '<_<' => "<img src='img/smiley/whatever.gif' alt='<_<' />",

    ':)' => "<img src='img/smiley/smile.gif' alt=':)' />",
    '=)' => "<img src='img/smiley/smile.gif' alt='=)' />",
    '=]' => "<img src='img/smiley/smile.gif' alt='=]' />",

    ':(' => "<img src='img/smiley/sad.gif' alt=':(' />",
    '=(' => "<img src='img/smiley/sad.gif' alt='=(' />",
    '=[' => "<img src='img/smiley/sad.gif' alt='=[' />",

   ':S' => "<img src='img/smiley/confused.gif' alt=':S' />",
   '=S' => "<img src='img/smiley/confused.gif' alt='=S' />",

   '8)' => "<img src='img/smiley/cool.gif' alt='8)' />",

   ':O' => "<img src='img/smiley/surprised.gif' alt=':O' />",
   '=O' => "<img src='img/smiley/surprised.gif' alt='=O' />",

   ':P' => "<img src='img/smiley/tongue.gif' alt=':P' />",
   '=P' => "<img src='img/smiley/tongue.gif' alt='=P' />",

   ';)' => "<img src='img/smiley/wink.gif' alt=';)' />",

   ':|' => "<img src='img/smiley/neutral.gif' alt=':|' />",
   '=|' => "<img src='img/smiley/neutral.gif' alt='=|' />",

    ':D' => "<img src='img/smiley/grin.gif' alt=':D' />",
    '=D' => "<img src='img/smiley/grin.gif' alt='=D' />"
);


Now when I put

 :) =)  >:D

it outputs

(evil smiley)' /> (smiley) (evil smiley)' />


So its somewhat like:
 >:D' />   :)   >:D' />

!@#$%. I need to go to bed. Sorry for editing this accidentally.
« Last Edit: October 07, 2008, 04:16:30 am by Darklight »
Logged
  • For The Swarm
Re: ehhh, noob question
« Reply #3 on: October 07, 2008, 04:14:49 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3374
...then I've got no idea. sorry.
Logged
Quote from: Jason
Your community is a bunch of stuck up turds.
Re: ehhh, noob question
« Reply #4 on: October 07, 2008, 11:44:50 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Odd though, its not doing a double replace is it? Eg. replacing the main smiley, then replacing this part of the output;

Code: [Select]
alt='>:)'

Also FYI thats not really a parser :P. Just a mass string replacement.
Logged

Xiphirx

wat
Re: ehhh, noob question
« Reply #5 on: October 07, 2008, 03:50:38 pm »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
Odd though, its not doing a double replace is it? Eg. replacing the main smiley, then replacing this part of the output;

Code: [Select]
alt='>:)'



Also FYI thats not really a parser :P. Just a mass string replacement.

well if I put

> : )

then : )

It should turn the first into a <img blah> wouldn't it? then it would look for : ) but wouldn't find it....

Code: [Select]
Also FYI thats not really a parser :P. Just a mass string replacement.

Parser sounds cooler :P
Logged
  • For The Swarm
Re: ehhh, noob question
« Reply #6 on: October 07, 2008, 03:51:51 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Quote
It should turn the first into a <img blah> wouldn't it? then it would look for : ) but wouldn't find it....
No, it replaces ALL instances of ALL strings. Dunno if it goes over replaced text though, might cause infinite-loops. Not sure, just a random thought.
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.056 seconds with 49 queries.

anything