Is there a difference between using backslash and simple?

Asked

Viewed 885 times

2

I wonder if when it comes to doing upload of a file, like this:

$destino = 'imagens/' . $novoNome;

There is a difference between imagens/ and imagens\?

1 answer

3


It depends on the context. If it is for use as a directory separator, PHP abstracts this and uses what is most suitable for the platform that is running. It does not mean that it will always work as expected, but in general it is so. It is usually preferred to use the normal bar and not the inverted one. Some people prefer to use DIRECTORY_SEPARATOR or even create functions to abstract the use of paths.

If it’s just one string normal makes a lot of difference in some cases. The normal bar is just a bar, the backslash is an indicating that the next character is special, so a \n is to skip a line, \t is a tabulation or \\ is when you want the backslash to be used as the normal character. But this depends on whether you are using single or double quotes, in the case of the simple used the only time the reverse does something different is when it uses \' to indicate that the string and rather wants an apostrophe to be used.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.