Skip to content

Instantly share code, notes, and snippets.

@lenivene
Created August 2, 2017 19:58
Show Gist options
  • Save lenivene/328190be1213807b79cbb4d922fd7716 to your computer and use it in GitHub Desktop.
Save lenivene/328190be1213807b79cbb4d922fd7716 to your computer and use it in GitHub Desktop.
Using an array as needles in mb_strpos
<?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