note 47115 deleted from function.strstr by betz

From: Date: Wed, 03 Nov 2004 16:39:48 +0000
Subject: note 47115 deleted from function.strstr by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79555@lists.php.net to get a copy of this message
Note Submitter: webmaster at hoskinscientifique dot com ---- to answer chris_mdq at yahoo dot com 27-Oct-2004 06:58 If you want to search some part of a text in a value, YOU DONT NEED to add a space at the beginning! just add a '!== false' (there is two equals signs) wich verifies if strpos doesnt return false thats because strpos returns 0 if it finds the char at the begining of the string (wich is position 0) and your 'if()' clause evaluates negatively. thats why you have to use the === or !== false. <?php $needle = '0'; $haystack = '1234567890'; if (strpos($haystack, $needle)!==false) { echo "The haystack contains $needle"; } else { echo "The haystack does not contains \"$needle\" "; } ?>

« previous php.notes (#79555) next »