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
 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC