Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7762501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:25:16+00:00 2026-06-01T14:25:16+00:00

This has me thrown for a loop: $s = ERROR: 5 – [RecordN…blah blah

  • 0

This has me thrown for a loop:

$s = "ERROR: 5 - [RecordN...blah blah blah";
print stripos($s, 'error') . "\n";
print strpos($s, "ERROR") . "\n";
print $s . "\n";

results in:

0
0
ERROR: 5 - [RecordN...blah blah blah

Huh? All right I’ll try something from here:

$mystring = 'abc';
$findme   = 'a';
$pos = strpos($mystring, $findme);

print $pos . "\n";

result is:

0

what?

I’m running:

php --version

PHP 5.3.6-13ubuntu3.6 with Suhosin-Patch (cli) (built: Feb 11 2012 03:26:01) 
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

Am I looking at a bug?

Thanks in advance.

EDIT:

Clearly lost my senses there. Thanks for all the responses.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:25:18+00:00Added an answer on June 1, 2026 at 2:25 pm

    Everything is correct. You are getting zeros because on the first occasion stripos returns 0 as the position of “e” (or “E”), whereas on the second occasion the zero is simply FALSE being printed as an integer.

    If you check manual for stripos, you will see that the return value description is

    Returns the position of where the needle exists relative to the
    beginnning of the haystack string (independent of offset). Also note
    that string positions start at 0, and not 1.

    Try changing your code to this and you will see what I mean:

    $s = "ERROR: 5 - [RecordN...blah blah blah";
    var_dump(stripos($s, 'error'));
    var_dump(strpos($s, "ERROR"));
    
    var_dump(strpos($s, 'error'));
    var_dump(stripos($s, "ERROR"));
    
    print $s . "\n";
    

    #1, #2 and #4 will be int(0) and #3 will be bool(false).

    The exact same thing is happening in your second example. You are checking for position of “a”, which is actually the first character in the string again, which means that its position is 0.

    If you need to check if the string is an error you should change your code from (supposedly) this:

    $s = "ERROR: 5 - [RecordN...blah blah blah";
    $isError = stripos($s, 'error') != 0;
    

    to this:

    $s = "ERROR: 5 - [RecordN...blah blah blah";
    $isError = (stripos($s, 'error') !== false);
    

    Or make it case sensitive if required:

    $s = "ERROR: 5 - [RecordN...blah blah blah";
    $isError = (strpos($s, 'ERROR') !== false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The WCF starter kit has WebProtocolException to throw exceptions in WCF. Is this included
This has been a problem that I haven't been able to figure out for
This has been an adventure. I started with the looping duplicate query located in
This has been driving me crazy for a few days. Why doesn't the following
This has happened to me 3 times now, and I am wondering if anyone
This has got to be something I just missed, but how do I add
This has been troubling me for a few years, and was recently exacerbated by
This has got to be something simple: I set up a frames page with
This has bugged me for a long time. 99% of the time, the GROUP
Q: I want to break the loop if some exception has been caught in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.