str_replace "\" with "/"

What is the correct way to format and str_replace to change a backslash to a forward slash? I've tried:

str_replace( '\', '/', $string );

But that produces an error.
MaybeItsJeremyAsked:
Who is Participating?
 
Diablo84Commented:
Remember the backslash is the escape character so you have to escape the backslash with another backslash effectively, for example:

$string = "hello \ there";
$string = str_replace( '\\', '/', $string );
echo $string;

Diablo84
0
 
MaybeItsJeremyAuthor Commented:
Hahahahaha. I knew that, but for some reason I kept trying to edit different things on the second parimeter instead of the first. Thank you. :)
0
 
Diablo84Commented:
no problem :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.