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 Quote 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... Quote 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); Quote 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 Quote 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); Quote Link to comment https://forums.phpfreaks.com/topic/83816-filtering-common-words/#findComment-426493 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.