kevinkhan Posted February 21, 2011 Share Posted February 21, 2011 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 https://forums.phpfreaks.com/topic/228377-does-anyone-know-a-function-i-could-use-instead-of-stristr/ Share on other sites More sharing options...
Pikachu2000 Posted February 21, 2011 Share Posted February 21, 2011 Can you clarify this please? "I only want it too return true if all the match corresponds with one of the element in the array $schoolList" Link to comment https://forums.phpfreaks.com/topic/228377-does-anyone-know-a-function-i-could-use-instead-of-stristr/#findComment-1177633 Share on other sites More sharing options...
Psycho Posted February 21, 2011 Share Posted February 21, 2011 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 https://forums.phpfreaks.com/topic/228377-does-anyone-know-a-function-i-could-use-instead-of-stristr/#findComment-1177645 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.