1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| <?php
function tableauMotsCensures() {
$row = 1;
$censure = array();
if (($csv = fopen("censure.csv", "r")) !== FALSE) {
while (($data = fgetcsv($csv, 1000, ",")) !== FALSE){
$num = count($data);
$row++;
for ($c=0; $c < $num; $c++) {
array_push($censure,$data[$c]);//ceci est un tableau PHP
}
}
fclose($csv);
return $censure;
}
}
$maChaine='coucou je veux voir si ma chaine possède un mot tabou tutu et pourquoi pas plusieurs tata !';
$mesMots=explode(' ',$maChaine);
$mesMotsInterdits=tableauMotsCensures();
$maChaineNettoyee='';
foreach($mesMots as $unMot){
if(in_array($unMot,$mesMotsInterdits)){
//on ne fait rien
}
else{
$maChaineNettoyee.=$unMot.' ';
}
}
echo $maChaineNettoyee;//si tutu et tata étaient sur le csv, ils disparaissent
?> |
Partager