note 68370 deleted from function.strpos by nlopess

From: Date: Tue, 25 Jul 2006 11:24:13 +0000
Subject: note 68370 deleted from function.strpos by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-115127@lists.php.net to get a copy of this message
Note Submitter: gooz at SPAMISFORBREAD dot gooz dot NL ---- 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

« previous php.notes (#115127) next »