php - >从数组中删除包含黑名单中单词的项目

Lup*_*upo 2 php arrays

我有一个包含几条Twitter推文的数组,想要删除此数组中包含以下单词之一的所有推文blacklist | blackwords | somemore

谁可以帮我解决这个案子?

Kal*_*sin 6

这是一个建议:

<?php
$banned_words = 'blacklist|blackwords|somemore';
$tweets = array( 'A normal tweet', 'This tweet uses blackwords' );
$blacklist = explode( '|', $banned_words );

//  Check each tweet
foreach ( $tweets as $key => $text )
{
    //  Search the tweet for each banned word
    foreach ( $blacklist as $badword )
    {
        if ( stristr( $text, $badword ) )
        {
            //  Remove the offending tweet from the array
            unset( $tweets[$key] );
        }
    }
}
?>
Run Code Online (Sandbox Code Playgroud)