- preg_replace: documentation ( source)
<?php
$string = '
<foo>ciao</foo>
<i>ex</i>
<asd>boh</asd>
<i>ex </i>
<i> testo con spazi </i>
<i>boh</i>
<asd>boh</asd>
';
$string = preg_replace('#<i>(.+)([\s]+)</i>#', '<i>\1 :)</i>', $string);
echo $string;