从mysql行中的字符串中删除一个单词

时间:2011-08-22 16:17:08

标签: php

我试图从我的数据库中的字符串中删除一个单词

字符串为$keywords = tech,sms,libya,tax

假设我想从字符串中删除libya我该怎么做呢

2 个答案:

答案 0 :(得分:3)

我认为为了清晰起见,您可能希望将字符串分解为数组,删除不需要的元素,然后重新构建字符串。像这样:

$keywords = 'tech,sms,libya,tax';       // Set String
$keywords = explode(',', $keywords);    // Explode into array
unset($keywords[ array_search('libya', $keywords) ]);   // Unset the array element with value of 'libya'
$keywords = implode(',',$keywords);     // Reconstruct string

答案 1 :(得分:1)

使用MySQL的REPLACE功能。