When a user wants to send a message, he can use emoticons. What happens, is that a users clicks on an emoticon, so that it inserts the corresponding text, like this:
:D
Now, after the message has been sent, the other person wants to see it. What I want is to replace the :D with an image...
Here is what I got:
$patterns = array();
$patterns[0] = '/:)/';
$patterns[1] = '/:(/';
$patterns[2] = '/:D/';
$patterns[3] = '/:C/';
$patterns[4] = '/:A/';
$patterns[5] = '/:H/';
$patterns[6] = '/:L/';
$patterns[7] = '/:O/';
$patterns[8] = '/:S/';
$patterns[9] = '/;)/';
$replacements = array();
$replacements[0] = '<img alt=":)" border="0" src="./images/smileys/happy.png" width="25px" />';
$replacements[1] = '<img alt=":(" border="0" src="./images/smileys/sad.png" width="25px" />';
$replacements[2] = '<img alt=":D" border="0" src="./images/smileys/veryhappy.png" width="25px" />';
$replacements[3] = '<img alt=":C" border="0" src="./images/smileys/cry.png" width="25px" />';
$replacements[4] = '<img alt=":A" border="0" src="./images/smileys/angry.png" width="25px" />';
$replacements[5] = '<img alt=":H" border="0" src="./images/smileys/heart.png" width="25px" />';
$replacements[6] = '<img alt=":L" border="0" src="./images/smileys/love.png" width="25px" />';
$replacements[7] = '<img alt=":O" border="0" src="./images/smileys/nothing.png" width="25px" />';
$replacements[8] = '<img alt=":S" border="0" src="./images/smileys/scared.png" width="25px" />';
$replacements[9] = '<img alt=";)" border="0" src="./images/smileys/wink.png" width="25px" />';
preg_replace($patterns, $replacements, $bericht);
But these aren't the right Regexes...so I get a php error. In the near future I'd like to take a tutorial on how regexes work, but I hope someone can help me out now.
Is there a simple and quick way to do this? Preferably per pattern like I do now, not in 1 big regex.