note 88124 deleted from function.strpos by danbrown

From: Date: Mon, 12 Jan 2009 02:37:28 +0000
Subject: note 88124 deleted from function.strpos by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-149079@lists.php.net to get a copy of this message
Note Submitter: John Dough ---- Here is an easy way to test whether a string contains something. It is a function named "contains": function contains($mystring, $findme) { $pos = strpos($mystring, $findme); if ($pos === false) { return false; } else { return true; } } Usage Example: if ( contains($string, '@') ) { echo "The string contains an @."; } As other users mentioned below, this may not work if the "findme" is at 0 position. But it a quick, easy way to test something like: does the e-mail address contain an @ ?

« previous php.notes (#149079) next »