How can one efficiently remove the eighth occurrence of a specific character in a string using PHP?

To efficiently remove the eighth occurrence of a specific character in a string using PHP, you can use the `substr_count()` function to count the occurrences of the character, then use `strpos()` to find the position of the eighth occurrence, and finally use `substr()` to remove that specific occurrence.

$string = "This is a sample string with multiple occurrences of a character.";
$charToRemove = 'a';
$occurrenceCount = 0;
$position = 0;

while ($occurrenceCount < 8) {
    $position = strpos($string, $charToRemove, $position + 1);
    $occurrenceCount++;
}

if ($position !== false) {
    $string = substr($string, 0, $position) . substr($string, $position + 1);
}

echo $string;