开发者

Delete a word from a string in mysql row

开发者 https://www.devze.com 2023-03-30 09:47 出处:网络
Am trying to delete a word from a string in my database The string is $keywords = tech,sms,libya,tax S开发者_StackOverflowuppose i want to remove libya from the string how do i go about thisI think

Am trying to delete a word from a string in my database

The string is $keywords = tech,sms,libya,tax

S开发者_StackOverflowuppose i want to remove libya from the string how do i go about this


I think for the clarity you might want to explode the string into an array, remove the unwanted element and then reconstruct the string. Like this:

$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


Use MySQL's REPLACE function.

0

精彩评论

暂无评论...
验证码 换一张
取 消