note 57523 added to function.strpos

From: Date: Thu, 06 Oct 2005 12:42:28 +0000
Subject: note 57523 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-96506@lists.php.net to get a copy of this message
this function takes a space-deliminted string as a list of potential needles and runs it against another string as a haystack. the number of positive matches of needles within the haystack is returned as a rounded percentile. function keyMatch($needles,$haystack) { $nArray=split(" ",$needles); $found=0; $best=count($nArray); for($i=0;$i<count($nArray);$i++) { $pzn=strpos(strtoupper($haystack),strtoupper($nArray[$i])); if ($pzn>-1) { $found++; } } $pct=($found*100)/$best; return round($pct); } $test = keyMatch("the quick wolf","the quick brown fox jumps over the lazy dog"); echo($test); RESULT: 67 (because "the" and "quick" were found but "wolf" was not) ---- Manual Page -- http://www.php.net/manual/en/function.strpos.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57523 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57523&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57523&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57523&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57523&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57523&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57523&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57523&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57523&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#96506) next »