0

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

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

Suppose i want to remove libya from the string how do i go about this

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

Comments

1

Use MySQL's REPLACE function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.