我清理一个字符串数组中删除字符串:帮助str_replace()函数
$regex = array("subida", " de"," do", " da", "em", " na", " no", "blitz");
这是我使用的str_replace函数:
for($i=0;$i<8;$i++){
$twit = str_replace($regex[$i],'', $twit);
}
我如何让它只删除一个单词,如果它正好是字符串中的单词,我的意思是,我有以下短语: “#blitz na subida do alfabarra blitz” 它会返回我: “#alfabarra”, 我不想第一个“闪电战”被删除,因为它有一个哈希“#”,我希望它输出: “#blitz alfabarra”,可能吗?谢谢
您的变量('$ regex')的名称,你没有使用在所有的正则表达式是一种误导。实际上,'str_replace'接受和数组,所以你可以做'$ twit = str_replace($ regex,'',$ twit);' – 2011-05-02 13:29:04