How can you determine the number of occurrences of a specific string within a text using PHP?

To determine the number of occurrences of a specific string within a text using PHP, you can use the `substr_count()` function. This function takes two parameters: the text to search within and the specific string to count occurrences of. It returns the number of times the string appears in the text.

$text = "This is a sample text with sample words.";
$specificString = "sample";

$occurrences = substr_count($text, $specificString);

echo "The specific string '$specificString' appears $occurrences times in the text.";