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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.