Posted: Tue Aug 09, 2005 10:16 am
But then the word list would have to be availible in every order, wouldn't it?
And acheiving that seems to be the big problem...
And acheiving that seems to be the big problem...
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$array = array("blue", "red", "green", "blue", "blue");
print_r(array_keys($array, "blue"));Code: Select all
Array
(
[0] => 0
[1] => 3
[2] => 4
)the words do have to be next to eachother this is true.Grim... wrote:But the words have to be next to each other in the sentence, right?
Shiznatix, I have to ask because I'm intrigued...
Why?
Code: Select all
function sequentialOrderlessMatch($subject,$words,$matchStarted=FALSE) {
foreach($words as $aWord) {
$pos = strpos($subject,$aWord);
if ($pos!==FALSE && (!$matchStarted || $pos==0)) {
$newSubject = substr($subject,strlen($aWord)+1);
$newWords = array_diff($words,array($aWord))l
$found = sequentialOrderlessMatch($newSubject,$newWords,TRUE);
}
if (!$found) continue;
}
return $found;
}Code: Select all
$oldlines = implode(' ', $arrlines);
for ($i=0; $i<count($keys); $i++)
{
if (false !== strpos($oldlines, $keys[$i]))
{
$somt = explode(' ', $keys[$i]);
$con = count($somt);
$temp = preg_replace('/'.$keys[$i].'/', '¤', $oldlines, 1);
$temp = str_replace(' ', ' ', $temp);
$temp = str_replace(' ', ' ', $temp);
$newtemp = explode(' ', $temp);
for($b=0; $b<count($newtemp); $b++)
{
if ($newtemp[$b] == '¤')
{
$count = $b;
break;
}
}
$newlinesarr[$count] = '<a href="'.$filename.'">'.$keys[$i].'</a>';
for($c=$count; $c<$count+$con; $c++)
unset($arrlines[$c]);
}
}