How To Check If a String Starts with a Substring in PHP?

In this tutorial, this function performs a case-sensitive search and checks if a string starts with a substring in PHP.

1. Code:

    <?php 
	
	function checkStringStartsWithSubstring($string, $substring){
		$length = strlen($substring);
		return (substr($string, 0, $length) === $substring);
	}
	
	$string = "Soltuts.com1234 providing PHP tutorials, tips, tricks";
	$substring = "Soltuts";
	var_dump(checkStringStartsWithSubstring($string, $substring));
    ?> 

2. Example:

Input:

string input: "Soltuts.com1234 providing PHP tutorials, tips, tricks"
substring: "Soltuts"

Output:

output: true