jasonc Posted June 4, 2006 Share Posted June 4, 2006 for some reason this works but not if the searchquery is the first letter onwards of the list1 or list2 arrayscan someone see what i can do to fix this so i foind the string should it be at the start of the liststhankswhile ($row= mysql_fetch_row($result)) {$array[]=$row;}// remove items that are not needed from arraysfor ($i = 0; $i < $num; $i++) {$id = $array[$i][0];$list1 = $array[$i][1];$list1=explode("\r\n",$list1);foreach($list1 as $key=>$value) {// check for all lower case matchif(!strpos(strtolower($value), strtolower($search))) {unset($fromwishlist[$key]);}}$fromwishlist=implode("\r\n",$list1);$list2 = $array[$i][2];$list2=explode("\r\n",$list2);foreach($list2 as $key=>$value) {// check for all lower case matchif(!strpos(strtolower($value), strtolower($search))) {unset($list2[$key]);}}$list2=implode("\r\n",$list2);}Edit/Delete Message Quote Link to comment https://forums.phpfreaks.com/topic/11161-remove-part-of-string-that-is-not-in-search-query-string/ Share on other sites More sharing options...
poirot Posted June 4, 2006 Share Posted June 4, 2006 I don't know exactly what it does, but based on your problem, I think:(!strpos(strtolower($value), strtolower($search))) won't work, because when strpos = 0 it is "considered" false.You should use (strpos(strtolower($value), strtolower($search)) !== true).PHP type comparison tables - Manual:[a href=\"http://www.php.net/manual/en/types.comparisons.php\" target=\"_blank\"]http://www.php.net/manual/en/types.comparisons.php[/a] Quote Link to comment https://forums.phpfreaks.com/topic/11161-remove-part-of-string-that-is-not-in-search-query-string/#findComment-41738 Share on other sites More sharing options...
jasonc Posted June 4, 2006 Author Share Posted June 4, 2006 hi thanks that made sense and tried it but now it does not show any resultsstring = "cat\r\ndog\r\ncats"search = "cat"string would then = "cat\r\ncats" when the script runs[!--quoteo(post=379911:date=Jun 4 2006, 04:36 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 4 2006, 04:36 PM) [snapback]379911[/snapback][/div][div class=\'quotemain\'][!--quotec--]I don't know exactly what it does, but based on your problem, I think:(!strpos(strtolower($value), strtolower($search))) won't work, because when strpos = 0 it is "considered" false.You should use (strpos(strtolower($value), strtolower($search)) !== true).PHP type comparison tables - Manual:[a href=\"http://www.php.net/manual/en/types.comparisons.php\" target=\"_blank\"]http://www.php.net/manual/en/types.comparisons.php[/a][/quote] Quote Link to comment https://forums.phpfreaks.com/topic/11161-remove-part-of-string-that-is-not-in-search-query-string/#findComment-41743 Share on other sites More sharing options...
poirot Posted June 4, 2006 Share Posted June 4, 2006 But did it show results before?If yes, check again if you added the code properly.If not, then you should re-do your code :P Quote Link to comment https://forums.phpfreaks.com/topic/11161-remove-part-of-string-that-is-not-in-search-query-string/#findComment-41745 Share on other sites More sharing options...
jasonc Posted June 4, 2006 Author Share Posted June 4, 2006 before the code i had it shows the results ok, but not if the first word was looked for, if string was"cat\r\ndog\r\ncats"and a search for "cat"before string would = "cats" but should really be "cat\r\ncats"[!--quoteo(post=379918:date=Jun 4 2006, 04:54 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 4 2006, 04:54 PM) [snapback]379918[/snapback][/div][div class=\'quotemain\'][!--quotec--]But did it show results before?If yes, check again if you added the code properly.If not, then you should re-do your code :P[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/11161-remove-part-of-string-that-is-not-in-search-query-string/#findComment-41748 Share on other sites More sharing options...
poirot Posted June 4, 2006 Share Posted June 4, 2006 What happens now? Quote Link to comment https://forums.phpfreaks.com/topic/11161-remove-part-of-string-that-is-not-in-search-query-string/#findComment-41759 Share on other sites More sharing options...
jasonc Posted June 4, 2006 Author Share Posted June 4, 2006 ANSWER....(!strstr(strtolower($value), strtolower($search)))thanks for your help. could not have done it without it.[!--quoteo(post=379932:date=Jun 4 2006, 05:17 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 4 2006, 05:17 PM) [snapback]379932[/snapback][/div][div class=\'quotemain\'][!--quotec--]What happens now?[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/11161-remove-part-of-string-that-is-not-in-search-query-string/#findComment-41760 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.