Я пишу код для индексации слов для своей поисковой системы. Что-то вроде:Получение ошибки: Неопределенное смещение
$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
. каков способ ее исправить?
Вы просто предполагаете, что регулярное выражение соответствует чему-то и на нем накладывается петля. –