How can PHP be used to replace one or more spaces in a string with another character?

To replace one or more spaces in a string with another character in PHP, we can use the `str_replace()` function. We can specify the space character as the search string and the desired character as the replacement string. This function will replace all occurrences of the space character with the specified character in the given string.

<?php
$string = "Hello World";
$newString = str_replace(' ', '-', $string);
echo $newString; // Output: Hello-World
?>