note 107050 deleted from function.strpos by danbrown

From: Date: Tue, 03 Jan 2012 21:45:10 +0000
Subject: note 107050 deleted from function.strpos by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-185280@lists.php.net to get a copy of this message
Note Submitter: eddyerkelens at gmail dot com ---- 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; } ?>

« previous php.notes (#185280) next »