Jump to content

matches "ishwasher" but not "dishwasher"


devknob

Recommended Posts

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

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) {...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.