Skip to content
PHP Logo

How can the code be modified to ensure that the replacement of "html" with ".html" is successful?

The issue with the current code is that the replacement function is not finding the exact match for "html" and replacing it with ".html". To ensure successful replacement, we can use the `str_replace()` function with the exact match of "html" as the first argument and ".html" as the second argument.

php
<?php
// Original string
$string = "index.html";

// Replace "html" with ".html"
$modified_string = str_replace("html", ".html", $string);

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