-1
Hello,
I need to present the result of a foreach out of the loop. The way I have been doing only presents one result. What I’m doing wrong?
//Check bad words
$badWords = array('palavra1', 'palavra2', 'palavra3');
$string = "A palavra1 é igual a palavra2 que é diferente da palavra3";
$matches = array();
$matchFound = preg_match_all(
"/\b(" . implode($badWords,"|") . ")\b/i",
$string,
$matches
);
if ($matchFound) {
$words = array_unique($matches[0]);
foreach($words as $word) {
$p[i] = $word;
$i++;
}
echo '<div class="notice notice-danger">A historia contém palavras censuradas, não poderá ser publicada. (';
print_r($p[i]);
echo ' ) </div>';
die();
}
And how do I remove the word "Array" from the result? Now the result is:(Array ( [0] => word1 [1] => word2 [2] => word3 ) and I wanted it to be just (word1, word2, word3)
– Bruno Serrano
I got echo implode( ', ', $p );
– Bruno Serrano
@Brunoserrano, I didn’t think that was the problem, I thought it was about the mistake that was making
– Miguel