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"; } } Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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) {... Quote Link to comment Share on other sites More sharing options...
devknob Posted August 26, 2010 Author Share Posted August 26, 2010 thanks a ton, workin =) Quote Link to comment 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.