从字符串中删除我想要的东西

I got a few keywords, symbols, letters etc I want to remove from my php string. I'm trying to add it but it doesn't work too well.

$string = preg_replace("/(?![=$'%-mp4mp3])\p{P}/u","", $check['title']);

pretty much I want to to remove word mp3, mp4, ./, apples from the string.

Please help guide me, thanks in advance!

You don't need regex for that.

$string = "Your original string here";
$keywords = array('mp3', 'mp4');
echo str_replace($keywords, '', $string);

First: [] in regular expression introduces a character class. A hyphen is used to represent a character range between two symbols. So the reason your regular expression would make too many erasures (as I suppose) is because [=$'%-mp4mp3] means =, $, ', everything from % to m (72 characters actually!), p, 3, 4.

Second: your regular expression doesn't grab "bad" characters/keywords. Actually, you erase punctuation after bad characters/keywords, as negative lookahead is meta sequence (it is not included in match).

Change your regex to:

"/[=$'%-]|mp3|mp4/u"