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
)
);
Ve sonra ben (orada kaç gülümsemeleri görmek için), ben döngü yalak bu diziyi Yorumu doğrulamak ve yorumun içeriği gülümseme maç ne zaman. Regex şöyle kullanılır:
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 o I "s: 10" girerseniz: "s: 10" ve "s: 1" yorumun içine, yukarıdaki kodu iki maç bulabilirsiniz. Düzenli ifadelerin bilgim çok kötü ve ben bunu çözemiyorum.