我有一个包含几条Twitter推文的数组,想要删除此数组中包含以下单词之一的所有推文blacklist | blackwords | somemore
谁可以帮我解决这个案子?
这是一个建议:
<?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)