Error: Warning: strpos () [function.strpos]: the offset is not contained in the string - cannot find a solution

I know this question has been asked, but, unfortunately, there are no answers how to solve this problem.

This appears in my log files:

PHP message: PHP Warning: strpos (): the offset is not contained in the line in ... on line 479

Unfortunately, I cannot understand what causes this problem and how to fix it. I tested this function many times (with large $ text, with short $ text, with $ spam words and without spam words), but I never get this error. So, what texts do my users submit that cause this error?

    if (strposab($text, $spam, 1)) {
    echo "Email addresses and URLs not allowed here";
die;
    }

$spam = array('http','www','hotmail','yahoo','gmail','msn');


function strposab($haystack, $needles=array(), $offset=0) {
$chr = array();
foreach($needles as $needle) {
$res = strpos($haystack, $needle, $offset);
if ($res !== false) $chr[$needle] = $res;
}
if(empty($chr)) return false;
return min($chr);
} 

Second question:

For some reason, this function does not filter the first word of the string. For example, the word "hotmail" was not found in this string function:

$text = 'hotmail test test test test';

"hotmail":

$text = 'test hotmail test test test test';
+5
3

:

, - . Offset strpos , $needle. 0, , , 0, ( 0.)

:

, 0, $needle, , $haystack, , $offset 1. $offset = 1 , , : 'otmail test test test test'.

:

stripos, strpos , , , .

+1

.

+2

, . , :

$text = 'hotmail test test test test';

.. if

if (strposab($text, $spam, 1))

1, "hotmail" 0. , 1, String:

otmail test test test test

...

hotmail test test test test

Secondly, if "hotmail" is at position 0, your strposab () function will return int (0), which is a non-Boolean value that, when used in a Boolean expression, is FALSE. Therefore you need to use the operator! == to avoid juggling. Thus, the correct if statement will be used:

if (strposab($text, $spam, 0) !== false)
+1
source

All Articles