note 17619 deleted from function.strcmp by jimw
| From: | jimw@php.net | Date: | Fri, 21 Dec 2001 00:35:19 +0000 |
| Subject: | note 17619 deleted from function.strcmp by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-23644@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);
?>