note 107050 added to function.strpos

From: Date: Tue, 03 Jan 2012 12:02:21 +0000
Subject: note 107050 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-185270@lists.php.net to get a copy of this message
I have made a quicker way to check if a $string is in a $other_string: <?php function in_string($haystack, $needle) { // check if $needle is not empty, if empty, return false if(empty($haystack) OR empty($needle)) { return false; } // use the strpos to find the position of its occurence $stripos = stripos($haystack, $needle); // look for its position using the triple-character-equation if($stripos === false OR $stripos !== true) { // return false return false; } else { // return true return true; } } ?> And shortend: <?php function in_string($h, $n) { if(empty($h)||empty($n)){return false;} $s = stripos($h, $n); return($s === false) ? false:true; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 77.169.189.97 ---- Manual Page -- http://www.php.net/manual/en/function.strpos.php Edit -- https://master.php.net/note/edit/107050 Del: integrated -- https://master.php.net/note/delete/107050/integrated Del: useless -- https://master.php.net/note/delete/107050/useless Del: bad code -- https://master.php.net/note/delete/107050/bad+code Del: spam -- https://master.php.net/note/delete/107050/spam Del: non-english -- https://master.php.net/note/delete/107050/non-english Del: in docs -- https://master.php.net/note/delete/107050/in+docs Del: other reasons-- https://master.php.net/note/delete/107050 Reject -- https://master.php.net/note/reject/107050 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#185270) next »