- preg_replace_callback: documentation ( source)
- in_array: documentation ( source)
<?php
$vocabolario = array("La", "mia", "una", "prova", "con", "del", "testo");
function wordCheck($word) {
global $vocabolario;
$word = $word[0];
if (in_array($word, $vocabolario)) {
return $word;
}
return '<u>'.$word.'</u>';
}
function textCheck($text) {
return preg_replace_callback('#(?!<.*?)\w+(?![^<>]*?>)#','wordCheck', $text);
}
echo textCheck("La mia รจ una provaa con del testo: <a href='http://pippo.it'>html</a>.");