note 90058 added to function.strpos

From: Date: Fri, 03 Apr 2009 20:57:27 +0000
Subject: note 90058 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-152797@lists.php.net to get a copy of this message
Note that strpos() will return false if you supply an integer (thus, this presumably applies to float, too) as needle. For example: <?php $id = 2; $text = '12345'; if(strpos($text, $id) === false){ echo 'Yes, is false'; } ?> Will output 'Yes, is false', a behavior which may not be very intuitive (you'd think it would be covered by PHP's type juggling feature). This can be easily fixed by adding $id = (string)$id; above the strpos() statement. ---- Server IP: 194.153.94.10 Probable Submitter: 84.75.143.181 ---- Manual Page -- http://www.php.net/manual/en/function.strpos.php Edit -- https://master.php.net/note/edit/90058 Del: integrated -- https://master.php.net/note/delete/90058/integrated Del: useless -- https://master.php.net/note/delete/90058/useless Del: bad code -- https://master.php.net/note/delete/90058/bad+code Del: spam -- https://master.php.net/note/delete/90058/spam Del: non-english -- https://master.php.net/note/delete/90058/non-english Del: in docs -- https://master.php.net/note/delete/90058/in+docs Del: other reasons-- https://master.php.net/note/delete/90058 Reject -- https://master.php.net/note/reject/90058 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#152797) next »