kpugazh Posted December 31, 2007 Share Posted December 31, 2007 Hi, I am doing a search program. For this I have to filter few words which are common. Sample, 'the', 'and', 'a', 'or' etc. I tried str_replace but didnt work fine as it replaced all a's in the string including the one within other words. I just want to filter these if it appears as complete word. Any help please post. Thanks Link to comment https://forums.phpfreaks.com/topic/83816-filtering-common-words/ Share on other sites More sharing options...
rajivgonsalves Posted December 31, 2007 Share Posted December 31, 2007 post your code you can do it using preg_replace... Link to comment https://forums.phpfreaks.com/topic/83816-filtering-common-words/#findComment-426489 Share on other sites More sharing options...
fert Posted December 31, 2007 Share Posted December 31, 2007 $text=str_replace(" a ","",$text); Link to comment https://forums.phpfreaks.com/topic/83816-filtering-common-words/#findComment-426490 Share on other sites More sharing options...
marcus Posted December 31, 2007 Share Posted December 31, 2007 Fert what if $text = "A dog is a mans best friend"; Your code would return A dog ismans best friend Link to comment https://forums.phpfreaks.com/topic/83816-filtering-common-words/#findComment-426491 Share on other sites More sharing options...
rajivgonsalves Posted December 31, 2007 Share Posted December 31, 2007 here you go $text=preg_replace("/\ba\b/i","",$text); Link to comment https://forums.phpfreaks.com/topic/83816-filtering-common-words/#findComment-426493 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.