devknob Posted August 24, 2010 Share Posted August 24, 2010 This code works, I am trying to disqualify certain keywords from a website I am scraping. For some reason, the D in the word dishwasher keeps a match from happening so i have to do this without the d. I just dont understand WHY. I tried it where both of them use Clean_String() which has a strtolower and tirm in it. The subject looks right, I tried utf8_encode() to make sure they were both the correct encoding but nothing works. Can anyone explain why the letter D is causing the word 'dishwasher' to not trigger strpos when I have the word 'dishwasher' in my disqualify array? $disqualify = array("ish-washer","ishwasher"); foreach($disqualify as $dis) { if(strpos(Clean_String($subject[0]), $dis)) { $status = 0; $color = "FF0000"; } } Link to comment https://forums.phpfreaks.com/topic/211580-matches-ishwasher-but-not-dishwasher/ Share on other sites More sharing options...
devknob Posted August 24, 2010 Author Share Posted August 24, 2010 echo Clean_String($subject[0]); this ouputs: dishwasher built-in Link to comment https://forums.phpfreaks.com/topic/211580-matches-ishwasher-but-not-dishwasher/#findComment-1102995 Share on other sites More sharing options...
devknob Posted August 24, 2010 Author Share Posted August 24, 2010 i know encoding and datatypes can cause confusion, but this is string for string, and i did the utf8 encode too.... Are there any other potential reasons why "dishwasher" is not equal to "dishwasher" (yeah the same string) in php? Link to comment https://forums.phpfreaks.com/topic/211580-matches-ishwasher-but-not-dishwasher/#findComment-1103005 Share on other sites More sharing options...
Mchl Posted August 24, 2010 Share Posted August 24, 2010 From manual entry for strpos Returns the position as an integer. If needle is not found, strpos() will return boolean FALSE. So when you look for 'dishwasher' in 'dishwasher' it returns 0. 0 cast to boolean evaluates to false.You need type comparison here. if(strpos(Clean_String($subject[0]), $dis) !== false) {... Link to comment https://forums.phpfreaks.com/topic/211580-matches-ishwasher-but-not-dishwasher/#findComment-1103066 Share on other sites More sharing options...
devknob Posted August 26, 2010 Author Share Posted August 26, 2010 thanks a ton, workin =) Link to comment https://forums.phpfreaks.com/topic/211580-matches-ishwasher-but-not-dishwasher/#findComment-1104068 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.