note 47115 added to function.strstr

From: Date: Wed, 03 Nov 2004 16:09:16 +0000
Subject: note 47115 added to function.strstr
Groups: php.notes 
Request: Send a blank email to php-notes+get-79549@lists.php.net to get a copy of this message
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\" "; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.strstr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47115 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47115&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47115&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47115&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47115&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47115&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47115&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47115&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#79549) next »