tags:

views:

33

answers:

3

Does anyone know any other way that I can use (beside of @strpos()) to ignored the error message that display from strpos() (Warning: strpos() [function.strpos]: Offset not contained in string in ....)

+3  A: 

Sounds like your third argument is not valid. From the docs

The optional offset parameter allows you to specify which character in haystack to start searching. The position returned is still relative to the beginning of haystack.

So, how about fixing your code instead of ignoring errors?

Ed Swangren
+5  A: 

Instead of doing something like this:

$pos = strpos($haystack, $needle, $offset);

do something like

if($offset < strlen($haystack))
    $pos = strpos($haystack, $needle, $offset);
else
    $pos = false; // Mimics the actual output of strpos

Hope this helps!

mattbasta
You also get an error if $offset is less than zero... so you could just tack that on to the if statement too.
Peter Ajtai
A: 

To answer the question, you can write your own error handler and catch that specific warning and suppress it... but I agree with the others; it's better that you just go and fix your code.

Michael Madsen