Created
August 2, 2017 19:58
-
-
Save lenivene/328190be1213807b79cbb4d922fd7716 to your computer and use it in GitHub Desktop.
Using an array as needles in mb_strpos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if( ! function_exists( 'mb_strpos' ) ){ | |
function mb_strpos( $haystack, $needles, $offset=0 ){ | |
return strpos( $haystack, $needle, $offset ); | |
} | |
} | |
function mb_strposa( $haystack, $needles = array(), $offset=0 ) { | |
$chr = array(); | |
foreach( $needles as $needle ){ | |
$res = mb_strpos( $haystack, $needle, $offset ); | |
if( $res !== false ) $chr[ $needle ] = $res; | |
} | |
if( empty( $chr ) ){ | |
return false; | |
} | |
return mb_min( $chr ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment