我正在编写一个代码来为我的搜索引擎索引单词。就像是:
$handle = fopen("http://localhost/ps-friend/index.php", "r");
while( $buf = fgets($handle,1024) )
{
/* Remove whitespace from beginning and end of string: */
$buf = trim($buf);
/* Try to remove all HTML-tags: */
$buf = strip_tags($buf);
$buf = preg_replace('/&\w;/', '', $buf);
/* Extract all words matching the regexp from the current line: */
preg_match_all("/(\b[\w+]+\b)/",$buf,$words);
/* Loop through all words/occurrences and insert them into the database(Not shown here): */
for( $i = 0; $words[$i]; $i++ )
{
for( $j = 0; $words[$i][$j]; $j++ )
{
$cur_word = addslashes( strtolower($words[$i][$j]) );
echo $cur_word;
}
}
}
当我回$cur_word
显为什么我不断收到错误Notice: Undefined offset: 2 in C:\xampp\htdocs\ps-friend\search.php on line 26
时,有时会在line 24
. 纠正它的方法是什么?