I have a variable having a path to a file which is like the following:
$path = "\home\ashutosh\Desktop\imgdone\0001.jpeg"
I want that \\
be replaced by this /
in order for me to read that path. I have used str_replace()
function to replace but the PHP code is not able to recognize that.
str_replace( "\", "/", $path );
Please help
you need to escape the \\
like that : str_replace('\\\\', '/', $path);
I explain a bit : "\\"
tell php to not end at the quote that follow \\
.
you use it in this case : "hello I'm \\"The Cat\\", the super hero"
. so the \\
is a special char, used to escape the one that follow. if you want to use it, you need to escape it with himself : \\\\
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.