I have this web page where users can add smilies to their comments. And I want to limit the number of smilies per comment. The "system" works but I have some problems with the regex part. I have my smilies defined in a config file like so:
$config['Smilies'] = Array (
// irrelevant stuff
'smilies' => Array (
':)' => 'smile.gif',
':(' => 'sad.gif',
// some more smilies
's:10' => 'worship.gif',
's:11' => 'zip.gif',
's:12' => 'heart.gif',
// some more smilies
's:1' => 'dry.gif',
's:2' => 'lol.gif',
's:3' => 'lollol.gif',
// some more smilies
)
);
And then when I validate the comment (to see how many smilies are there), I loop trough this array and match the smile to the content of the comment. The regex is used like this:
foreach ( $this->config['smilies'] as $smilie => $smilieImage )
{
$matches = Array ();
Preg_Match_All ( '/' . Preg_Quote ( $smilie ) . '/i', $Content, $matches );
$numOfFoundSmilies += Count ( $matches[0] );
}
The problem is that the if I enter "s:10" into the comment, the above code will find two matches: "s:10" and "s:1". My knowledge of regular expressions is very poor, and I can't figure this one out.