Are there alternative methods to replace only the first character of a text with an image in PHP, besides using str_replace?

One alternative method to replace only the first character of a text with an image in PHP is by using substr_replace function. This function allows you to replace a portion of a string with another string starting at a specified position. By using substr_replace, you can easily replace the first character of a text with an image without having to use str_replace.

$text = "Hello World";
$image = "<img src='image.jpg'>";

$text = substr_replace($text, $image, 0, 1);

echo $text;