What function can be used in PHP to determine how many times a string appears in a text?

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

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

$count = substr_count($text, $searchString);

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