Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper dfrapi_string_starts_with() function #1

Closed
EricBusch opened this issue Jan 18, 2018 · 0 comments
Closed

Add helper dfrapi_string_starts_with() function #1

EricBusch opened this issue Jan 18, 2018 · 0 comments
Assignees
Labels

Comments

@EricBusch
Copy link
Member

Add the following function:

/**
 * Returns true if the $string starts with one of the $patterns. Otherwise returns false.
 *
 * @param string $string The haystack.
 * @param string|array $patterns The patterns to search for in the beginning of the $string.
 *
 * @return bool
 */
function dfrapi_string_starts_with( $string, $patterns ) {
	$patterns = ( is_string( $patterns ) ) ? array( $patterns ) : $patterns;
	foreach ( $patterns as $pattern ) {
		$length = mb_strlen( $pattern );
		if ( mb_substr( $string, 0, $length ) === $pattern ) {
			return true;
		}
	}

	return false;
}
@EricBusch EricBusch added the enhancement New feature or request label Jan 18, 2018
@EricBusch EricBusch self-assigned this Jan 18, 2018
@EricBusch EricBusch added task and removed enhancement New feature or request labels Jan 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant