How can you convert all spaces to uppercase letters following a space in a PHP variable?

To convert all spaces to uppercase letters following a space in a PHP variable, you can use the str_replace() function to replace each space followed by a space with an uppercase space. This can be achieved by first replacing all spaces with a unique character, then replacing that character followed by a space with an uppercase space.

<?php
// Input string
$string = "hello world";

// Replace all spaces with a unique character
$string = str_replace(' ', '#', $string);

// Replace the unique character followed by a space with an uppercase space
$string = str_replace('# ', 'SPACE ', $string);

// Output the modified string
echo $string;
?>