How can the str_replace() function be utilized to handle placeholders in PHP?

When dealing with placeholders in PHP, the str_replace() function can be utilized to replace these placeholders with actual values. By using str_replace(), you can easily search for a specific placeholder string within a larger string and replace it with the desired value. This can be useful when working with templates or dynamic content that requires variable substitution.

// Define the placeholder and its corresponding value
$placeholder = '{name}';
$value = 'John Doe';

// Define the template string with the placeholder
$template = 'Hello, {name}!';

// Replace the placeholder with the actual value
$result = str_replace($placeholder, $value, $template);

// Output the result
echo $result;