Jump to content

String search question


wglenn01

Recommended Posts

Hey all,

I have a quick question and I know the answer is probably pretty easy but i've been working on it a while now and can't figure out how to get this done.

SOO the situation is. I am looping through an RSS feed and with each entry I want to search for a brand name within the title, and add a company logo beside the entry.  I was playing with something like this but it doesn't work real well..

 

// Find Kokatat
$find = "Kokatat";
if(strstr($string, $find)) {
$icon = "koksm.jpg";
} else {
	$icon = "";
}

 

I appreciate any input!

Link to comment
Share on other sites

Well what I mean is, it works as a single search but when I add another, below it to search for a different name, if the first one succeeds and sets $icon, then the second doesn't succeed and sets $icon to empty. Does that make sense?

 

I have 27 different names I need to loop through to see which one comes back with a match.

Link to comment
Share on other sites

Well what I mean is, it works as a single search but when I add another, below it to search for a different name, if the first one succeeds and sets $icon, then the second doesn't succeed and sets $icon to empty. Does that make sense?

 

I have 27 different names I need to loop through to see which one comes back with a match.

 

Several ways to do it.  Here's one:

 

$words = array('Kokatat'=>'koksm.jpg', 'Something'=>'something.jpg', 'Another'=>'123.jpg'); //etc...
$icon = '';

foreach($words as $search => $icon) {
   if(stripos($string, $search) !== false) {
      break;
   }
}
echo $icon;

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.