StartsWith e EndsWith


Aqui apresentamos 2 funções bastantes úteis para descobrir se a string 'começa com' ou 'termina com' determinado valor.


	function startsWith($fullstring, $search_string) {
		// search backwards starting from fullstring length characters from the end
		return $search_string === "" || strrpos($fullstring, $search_string, -strlen($fullstring)) !== false; 
	} 
	
	function endsWith($fullstring, $search_string) {
		// search forward starting from end minus search_string length characters
		return $search_string === "" || (($temp = strlen($fullstring) - strlen($search_string)) >= 0 && strpos($fullstring, $search_string, $temp) !== false);
	}





Comentários

Copyright © 2018 Anderson Bravo
www.andersonbravo.com.br
anderson@andersonbravo.com.br