How to update path with invalid slash?

I have an invalid path:

C:\xampp\htdocs\laposte\app\webroot\img/Penguins.jpg

how to change a line that has only forward slashes, like

C:/xampp/htdocs/laposte/app/webroot/img/Penguins.jpg

My idea is to extract words from a string and then rearrange the string using a forward slash.

how do you do it

+4
source share
4 answers

Use realpath .

$str = realpath("C:\\xampp\\htdocs\\laposte\\app\\webroot\\img/Penguins.jpg");
echo $str; //C:\xampp\htdocs\laposte\app\webroot\img\Penguins.jpg

Or directly:

$str = str_replace('\\', '/', $str);
echo $str; //C:/xampp/htdocs/laposte/app/webroot/img/Penguins.jpg
+2
source

I think your path is ok for windows, except for the last slash. It should be a backslash as follows: C: \ XAMPP \ HTDOCS \ laposte \ application \ Webroot \ IMG \ Penguins.jpg

0
source
0

php:

echo str_replace("\\","/","C:\xampp\htdocs\laposte\app\webroot\img/Penguins.jpg");
0

Source: https://habr.com/ru/post/1546667/


All Articles