php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14774 strpos with strtolower to working incorrectly
Submitted: 2001-12-30 10:45 UTC Modified: 2001-12-30 17:59 UTC
From: armtuk at yahoo dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 4.0.6 OS: Linux 2.4.9-7smp
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: armtuk at yahoo dot com
New email:
PHP Version: OS:

 

 [2001-12-30 10:45 UTC] armtuk at yahoo dot com
<?php

$query="insert into users (user_name) values 'user_name'";

if (strpos(strtolower($query),"select")==0)
{
   print "FISH!";
}

?>

Amazingly enough this prints FISH!.

but:

$query="insert into users (user_name) values 'user_name'";

if 
(strpos(strtolower($query),"select")==0&&!(strpos(strtolower($query,"select")===FALSE))
{
   print "FISH!";
}

does not.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-30 10:50 UTC] mfischer@php.net
Thats the documented and expected behaviour.
 [2001-12-30 10:54 UTC] georg@php.net
Sorry, but it works correct.

In your sample $query has no "insert", therefore strpos 
returns 0 (not found), as desribed in the manual.

 [2013-06-29 02:10 UTC] aledmb at gmail dot com
strpos has a bug.

the following statement should give 1, but gives zero:

echo strpos(strtolower('C'), 'c');
 [2013-06-29 02:15 UTC] aledmb at gmail dot com
please ignore my previous comment, i'm dumb... should be checking for false, as 
zero is a valid offset.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri May 24 01:01:26 2019 UTC