一個特定的單詞,我需要一些代碼,可刪除不包含特定單詞刪除不包含在PHP
,或者我們可以說,只有包含特定單詞保持和/濾波器陣列的所有行刪除所有其他的
哪一個使用較少的資源?
更新:正確的答案,我的問題是
<?php
$nomatch = preg_grep("/{$keyword}/i",$array,PREG_GREP_INVERT);
?>
通知的PREG_GREP_INVERT。
這將導致包含$ array的所有條目的數組($ nomatch),其中找不到$ keyword。
所以你必須刪除反轉並使用它:) $ nomatch = preg_grep(「/ {$ keyword}/i」,$ array);
現在就只能得到具有線條特定詞
相關:http://stackoverflow.com/questions/2267762/delete-the-line-contains-specific-words-phrases-with-php – trante 2013-03-07 17:15:59