note 85835 deleted from function.strpos by cmb

From: Date: Sun, 02 Jun 2019 09:02:09 +0000
Subject: note 85835 deleted from function.strpos by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-211179@lists.php.net to get a copy of this message
Note Submitter: mickRacky ---- here's a php implementation of stdc++ string class find_first_of using strpos. <?php function find_first_of($haystack, $needlesAsString, $offset=0) { $max = strlen($needlesAsString); $index = strlen($haystack)+1; for($ii=0; $ii<$max;$ii++){ $result = strpos($haystack,$needlesAsString[$ii], $offset); if( $result !== FALSE && $result < $index) $index = $result; } return ( $index > strlen($haystack)? FALSE: $index); } ?> Example: <?php $test="Ralph: One of these days, Alice!!"; $look_for=":!,"; // punctuation marks $ss = 0; while( $answer=find_first_of($test,$look_for,$ss) ) { echo $answer . "\n"; $ss = $answer+1; } ?> This prints out: 5 24 31 32

« previous php.notes (#211179) next »