-4

I have string in PHP like below

C:\xampp\htdocs

I want output of it using str_replace like

/xampp/htdocs

I am trying it like below

$path = getcwd();
$new = str_replace(array("C:", "\"), ("","/") $path);
echo $new;

but its giving me error like below

Parse error: syntax error, unexpected '","' (T_CONSTANT_ENCAPSED_STRING), expect ing ')' in C:\xampp\htdocs\install-new.php on line 16

Let me know what is wrong with it.

Adarsh
  • 303
  • 1
  • 3
  • 13
Hina Patel
  • 59
  • 6

2 Answers2

0

You are missing array declaration on the 2nd argument, as well as a comma before the 3rd argument $path. Lastly as noted in the comments, the \ needs to be escaped otherwise it escapes the closing quote:

This:

$new = str_replace(array("C:", "\"), ("","/") $path);

Should be:

$new = str_replace(array('C:', '\\'), array('','/'), $path);
0

It's because you escaped a double quote. You need to add an backslash to your second expression like that:

$path = getcwd();
$new = str_replace(array("C:", "\\"), ("","/") $path);
echo $new;
Simon30
  • 317
  • 3
  • 12