Вам, вероятно, нужно что-то подобное.
/i
для сопоставления без учета регистра (поскольку регистр может иметь значение).
<?php
$tweets = array("this is a #tiger tweet", "this is a #blood tweet", this is a #horror tweet");
$pattern = array("/#tiger/i", "/#blood/i", "/#horror/i");
for($i = 0; $i < count($pattern); $i++){
for($j = 0; $j < count($tweets); $j++){
preg_match($pattern[i], $tweets[j], $matches, PREG_OFFSET_CAPTURE);
print_r($matches); //check matches array and decide if you want to show tweet.
}
}
?>
или если вы не хотите использовать регулярные выражения.
<?php
$tweets = array("this is a #tiger tweet", "this is a #blood tweet", this is a #horror tweet");
$pattern = array("#tiger", "#blood", "#horror");
for($i = 0; $i < count($pattern); $i++){
for($j = 0; $j < count($tweets); $j++){
$tweet = strtolower(tweets[j]); //lowercase both because we we want to match the tag no matter what the case.
$pattern = strtolower(patterns[i]);
if(strpos(tweets[j], pattern[i]) > -1){
//show
}
}
}
?>
Надеюсь, это поможет.
С уважением,