What are common methods in PHP to replace backslashes with forward slashes in strings?

When working with file paths or URLs in PHP, it is common to need to replace backslashes (\) with forward slashes (/) for proper formatting. This can be achieved using the str_replace() function in PHP, which allows you to search for a specific character (in this case, a backslash) and replace it with another character (a forward slash).

$string = "C:\\xampp\\htdocs\\index.php";
$fixed_string = str_replace("\\", "/", $string);
echo $fixed_string;