林使我自己的功能來搜索的東西總數。但它不能正常工作。函數getNumberOfCounts獲取$ fromIndex但不是搜索詞爲什麼我不能發送一個字符串,但只有一個數字到成員函數?
public function getNumberOfCounts($searchWord, $fromIndex)
{
$index = $fromIndex;
$counter = 0;
while($index <= $endPos)
{
$index++;
$pos = strpos($this->text, $searchWord, ($index+1));
if($pos > $index)
{
$counter++;
$index = $pos;
}
else
break;
}
return $counter;
}
public function searchDemo()
{
$startPos = 11; // ex
echo "<br /> count= " . $this->getNumberOfCounts("Lorem", $startPos);
}
它們都是同一類c的一部分。
編輯:我知道有一些丟失的信息,但如果我嘗試在getNumberOfCounts的第一行上打印$ searchWord,則不會輸出任何內容。
您必須忽略一些重要的呢。這實際上不可能通過這個字符串。請發佈一個可以按原樣運行的示例來演示問題。 – deceze 2010-04-30 09:03:30