Risolto con
Codice PHP:
function emoticons($text) {
$icons = array(
':)' => '<img src="/images/blank.gif" alt="smile" class="icon_smile" />',
':-)' => '<img src="/images/blank.gif" alt="smile" class="icon_smile" />',
':D' => '<img src="/images/blank.gif" alt="smile" class="icon_laugh" />',
':d' => '<img src="/images/blank.gif" alt="laugh" class="icon_laugh" />',
';)' => '<img src="/images/blank.gif" alt="wink" class="icon_wink" />',
':P' => '<img src="/images/blank.gif" alt="tounge" class="icon_tounge" />',
':-P' => '<img src="/images/blank.gif" alt="tounge" class="icon_tounge" />',
':-p' => '<img src="/images/blank.gif" alt="tounge" class="icon_tounge" />',
':p' => '<img src="/images/blank.gif" alt="tounge" class="icon_tounge" />',
':(' => '<img src="/images/blank.gif" alt="sad face" class="icon_sad" />',
':o' => '<img src="/images/blank.gif" alt="shock" class="icon_shock" />',
':O' => '<img src="/images/blank.gif" alt="shock" class="icon_shock" />',
':0' => '<img src="/images/blank.gif" alt="shock" class="icon_shack" />',
':|' => '<img src="/images/blank.gif" alt="straight face" class="icon_straight" />',
':-|' => '<img src="/images/blank.gif" alt="straight face" class="icon_straight" />',
':/' => '<img src="/images/blank.gif" alt="straight face" class="icon_straight" />',
':-/' => '<img src="/images/blank.gif" alt="straight face" class="icon_straight" />'
);
return strtr($text, $icons);
}
E per evitare l'emoticon nei siti esempio http:// ho semplicemente evitato di mettere che l'emoticon :/ esista
In questo passaggio probabilmente c'è qualcosa di sbagliato:
Codice PHP:
foreach($icons as $icon=>$image) {
$icon = preg_quote($icon);
$text = preg_replace("~\b$icon\b~",$image,$text);
}