Possible Duplicate:
Replace a list of emoticons with their images
i'm developing a website where i want to give users possibility to put smiles on posts. My (just functional) idea is to use array in this way:
$emoticons = array(
array("17.gif",":)"),
array("6.jpg",":P"),
.....
array("9.jpg",":'("),
array("5.gif","X)")
);
with image on [0] and emoticon on [1]. And on each $post:
foreach($emoticons as $emoticon){
$quoted_emoticon = preg_quote($emoticon[1],"#");
$match = '#(?!<\w)(' . $quoted_emoticon .')(?!\w)#';
$post = preg_replace($match,'<img src="images/emoticons/'.$emoticon[0].'">',$post);
}
This is working good, but my problem is '#(?!<\w)('
and ')(?!\w)#'
because I want emoticons to apply only when preceding characters are "begin" (^
) or "blank" and succeeding characters are "end" ($
) or "blank". What is the right regex to do this?