note 88124 added to function.strpos

From: Date: Mon, 12 Jan 2009 02:34:50 +0000
Subject: note 88124 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-149078@lists.php.net to get a copy of this message
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 @ ? ---- Server IP: 208.69.120.35 Probable Submitter: 151.11.232.92 ---- Manual Page -- http://www.php.net/manual/en/function.strpos.php Edit -- https://master.php.net/note/edit/88124 Del: integrated -- https://master.php.net/note/delete/88124/integrated Del: useless -- https://master.php.net/note/delete/88124/useless Del: bad code -- https://master.php.net/note/delete/88124/bad+code Del: spam -- https://master.php.net/note/delete/88124/spam Del: non-english -- https://master.php.net/note/delete/88124/non-english Del: in docs -- https://master.php.net/note/delete/88124/in+docs Del: other reasons-- https://master.php.net/note/delete/88124 Reject -- https://master.php.net/note/reject/88124 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#149078) next »