My string looks like:
$fullPath = $dirName . \"/\" . $file;
If I replace / with \\, it gives error:
Expecting identifier
\
is an escape character. It is a special character used to define either escape sequences or to escape string-delimiters if you want to use them in the string itself.
The correct usage is to escape the escape character like this: \\
. This will tell the parser the you wanted the literal backslash and not the special meaning of it.
You need to escape the slash: $fullPath = $dirName . "\\" . $file;
You might use apostrophes to denote a non-parsed string:
$fullPath = $dirName . '\' . $file;
You need "\\"
because \
is an escape character.