Jump to content

does anyone know a function i could use instead of stristr


kevinkhan

Recommended Posts

I have an array with the following elements

 

define("LIST_OF_SCHOOLS", "st patricks,Piarsaigh,Phiarsaigh,St Vincents,Glanmire,Farranree,North Presentation,north mon,north monestrey,Scoil iosagain,St aidans,knocknaheeny,mon");

 

$schoolList = explode(',', LIST_OF_SCHOOLS);

 

function checkForSchool($page, $schoolList) {
   preg_match('%(Studied at|Went to|Goes to) \\\u003ca href=\\\\"http:\\\/\\\/www.facebook.com\\\/pages\\\/[a-zA-Z-]*\\\/\d*\\\\" data-hovercard=\\\\"\\\/ajax\\\/hovercard\\\/page.php\?[a-zA-Z=0-9]*\\\\">([a-zA-Z\s]*)\\\u003c\\\/a>%', $page, $match);
    if($match && count($match)>0) {

		normal($match[2]);
		for($cnt=0; $cnt<count($schoolList); $cnt++) {

			$school = trim($schoolList[$cnt]);

			green(stristr($match[2],$school));
			if($school!="" && stristr($match[2], $school)) { 
			blue($match[2].": Match for school found");
				unset($school);
				return true;
			}			
		}	
    }
else
{
red("No school set on profile");
}
unset($school);
return false;

How come my function is returning true for this match

 

mond Community High School

Inveralmond Community High School: Match for school found

 

I only want it too return true if all the match corresponds with one of the element in the array $schoolList

Link to comment
Share on other sites

You need to check the values that YOU THINK are being compared. Most likely you are getting a single character or something like that.

 

By the way, why are you looping through all the values in the array? Use in_array() instead. Just be sure the values in the search string and the array have the same case.

 

For debugging, before this line

if($school!="" && stristr($match[2], $school)) { 

 

Add:

echo "Comparing [{$school}] & [{$match[2]}]<br />\n";

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.