开发者

Anyway that I can ignored the error message from strpos()?

开发者 https://www.devze.com 2023-01-08 06:32 出处:网络
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]: Of开发者_如何学JAVAfset not contained

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]: Of开发者_如何学JAVAfset not contained in string in ....)


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!


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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消