Javascript:
function stristr( haystack, needle, bool ) { // Case-insensitive strstr()
//
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
var pos = 0;
pos = haystack.toLowerCase().indexOf( needle.toLowerCase() );
if( pos == -1 ){
return false;
} else{
if( bool ){
return haystack.substr( 0, pos );
} else{
return haystack.slice( pos );
}
}
}
Примеры:
stristr('Kevin van Zonneveld', 'Van');
'van Zonneveld'
stristr('Kevin van Zonneveld', 'VAN', true);
'Kevin '
|
|
|
|