note 68370 added to function.strpos

From: Date: Mon, 24 Jul 2006 22:21:24 +0000
Subject: note 68370 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-115106@lists.php.net to get a copy of this message
A simple solution to find out if a $string contains a $needle: if ( strpos( "X" . $string , $needle) ) > 0 ) { //It contains the $needle } else { //It contains NOT the $needle } Because of the adding of "X" to the string to be searched, strpos() gives not 0 or FALSE or whatever: it gives a value > 0. This nicer than 0, which maybe false and not correct because strpos( $string , $needle) ) gives 0 when: $string = "poo"; and $needle = "p"; Greetz, gooz ---- Server IP: 194.109.193.119 Probable Submitter: 80.56.252.37 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.strpos.php Edit -- http://master.php.net/note/edit/68370 Del: integrated -- http://master.php.net/note/delete/68370/integrated Del: useless -- http://master.php.net/note/delete/68370/useless Del: bad code -- http://master.php.net/note/delete/68370/bad+code Del: spam -- http://master.php.net/note/delete/68370/spam Del: non-english -- http://master.php.net/note/delete/68370/non-english Del: in docs -- http://master.php.net/note/delete/68370/in+docs Del: other reasons-- http://master.php.net/note/delete/68370 Reject -- http://master.php.net/note/reject/68370 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#115106) next »