note 17619 added to function.strcmp
| From: | oliver dot ahlberg at NO_SPAM_sydostpress dot se | Date: | Mon, 17 Dec 2001 13:45:32 +0000 |
| Subject: | note 17619 added to function.strcmp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-22983@lists.php.net to get a copy of this message | ||
Determines the string which is in common for all variables in the passed array. Can be used to
remove complete references from an array filled with file locations.
This one goes from left to right, but it can easily be changed into the opposite if desired.
<?php
function strComp($array) {
while (!$quit) {
$offset++;
$srchChr = substr($array[0],0,$offset);
for ($i = 0; $i < sizeof($array); $i++) {
if (substr($array[$i],0,$offset) != $srchChr) {
$quit = true;
}
}
}
return substr($srchChr,0,strLen($srchChr)-1);
}
$array[] = "My name is Tom";
$array[] = "My name is Sam";
$array[] = "My name is Ted";
$array[] = "My name is Sal";
echo strComp($array);
?>
--
http://www.php.net/manual/en/function.strcmp.php
http://master.php.net/manage/user-notes.php?action=edit+17619
http://master.php.net/manage/user-notes.php?action=delete+17619
http://master.php.net/manage/user-notes.php?action=reject+17619