|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-10-21 14:50 UTC] runkharr at googlemail dot com
-Status: Open
+Status: Closed
[2013-10-21 14:50 UTC] runkharr at googlemail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 25 18:00:01 2025 UTC |
Description: ------------ strpos ($string, $number) returns FALSE, whereas strpos ($string, (string) $number) returns the first occurrence of the (stringified) number. The same is true for older versions of PHP. May be this is intended, but a small comment about this behaviour would be helpful. The real problem is that (during the reading of configuration files or database values) sometimes an automatical conversion takes place, so that $number, which needs to be interpreted as a string in the example above, is instead interpreted as numerical value. This leads to problems in some programs, which (e.g.) search for a number in a comma-separated list of numbers. Without knowing the behaviour of 'strpos()', one may sometimes search hours and hours for a problem which could be solved with a simple remark in the documentation. Test script: --------------- <?php $a = '49,35'; $b = 35; $c = (string) $b; print "strpos('$a', '$b') = ".strpos($a, $b)."\n"; print "strpos('$a', '$c') = ".strpos($a, $c)."\n"; ?>