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

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

1. Code:

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

2. Example:

Input:

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

Output:

output: true