What is the purpose of using substr_count in PHP?

The substr_count function in PHP is used to count the number of occurrences of a substring within a given string. This can be useful when you need to determine how many times a specific sequence of characters appears in a larger string. By using substr_count, you can easily retrieve this information without having to manually iterate through the string.

$string = "Hello, hello, hello!";
$substring = "hello";
$count = substr_count($string, $substring);

echo "The substring '$substring' appears $count times in the string.";