chooseodie Posted May 15, 2007 Share Posted May 15, 2007 Hi; I have a "latest 10 search queries" function on my site. And i want to exclude some words from results. For example "pee". Thanks... Quote Link to comment https://forums.phpfreaks.com/topic/51467-exclude-some-text-from-results/ Share on other sites More sharing options...
Dragen Posted May 15, 2007 Share Posted May 15, 2007 what code do you have to display the results? Quote Link to comment https://forums.phpfreaks.com/topic/51467-exclude-some-text-from-results/#findComment-253448 Share on other sites More sharing options...
chigley Posted May 15, 2007 Share Posted May 15, 2007 <?php $excluded = array("pee", "poo"); $string = "my mum likes to poo whilst she has a pee"; $replace = "!#@?"; foreach($excluded as $word) { $string = str_replace($word, $replace, $string); } echo $string; ?> Quote Link to comment https://forums.phpfreaks.com/topic/51467-exclude-some-text-from-results/#findComment-253457 Share on other sites More sharing options...
chooseodie Posted May 15, 2007 Author Share Posted May 15, 2007 Thanks a lot Dragen & chigley. I got it but when i search like peeling it gives !#@?ling. I want to exclude only pee word. Any ideas? thanks... Quote Link to comment https://forums.phpfreaks.com/topic/51467-exclude-some-text-from-results/#findComment-253476 Share on other sites More sharing options...
Dragen Posted May 15, 2007 Share Posted May 15, 2007 probably not the best way, but try changing $exclude to this: $excluded = array(" pee ", " poo "); Just adding spaces before and after to seperate them as individual words. Quote Link to comment https://forums.phpfreaks.com/topic/51467-exclude-some-text-from-results/#findComment-253479 Share on other sites More sharing options...
chooseodie Posted May 15, 2007 Author Share Posted May 15, 2007 :(not working. This time codes did not exclude anything. Quote Link to comment https://forums.phpfreaks.com/topic/51467-exclude-some-text-from-results/#findComment-253484 Share on other sites More sharing options...
chigley Posted May 15, 2007 Share Posted May 15, 2007 <?php $excluded = array(" pee ", " poo "); $string = "my mum likes to poo whilst she has a pee and also often is peeing"; $replace = " !#@? "; foreach($excluded as $word) { $string = str_replace($word, $replace, $string); } echo $string; ?> Works fine for me that way? Quote Link to comment https://forums.phpfreaks.com/topic/51467-exclude-some-text-from-results/#findComment-253728 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.