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... 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? 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; ?> 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... 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. 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. 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? 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
Archived
This topic is now archived and is closed to further replies.