Asked  9 Months ago    Answers:  5   Viewed   41 times

Can anyone tell me what is happening here?

// true
var_dump('\ ' === ' ');

// false
var_dump('\\ ' === '\ ');

// true
var_dump('\\ ' === '\ ');



inside a string literal introduces several types of escape sequences, \ is the escape sequence for a literal "". But, s that don't resolve to an escape sequence are also taken as literal "".

Therefor, '\ ' stands for the string " ", '\\ ' stands for the string "\ ", just as '\ '. Try:

echo '\\ ';   -> \ 


Wednesday, March 31, 2021
answered 9 Months ago

Which are the characters do you have to escape?

You could use single quotes [docs]. The only characters that have to be escaped in such a string are and '.

If you have a long string, also have a look at heredoc [docs].

Wednesday, March 31, 2021
answered 9 Months ago

Try out NETTuts and their "From Scratch" series. Very useful for new users.

Wednesday, March 31, 2021
answered 9 Months ago

$str contains a string with the content of "$var" (no variable replacement, just these very characters). It was created using single quotes, so no variable replacement there.

When echoing it using echo "$str", the variable $str gets replaced with its content, namely the string "$var", thus resulting in your output.

The string replacement in double quotes strings does not work recursively! So in order to have $str replaced by 1024 in the second appearance, you have to create $str using double quotes in the first place.

Saturday, May 29, 2021
answered 7 Months ago

For security reasons, it is not possible to get the real, full path of a file, referred through an <input type="file" /> element.

This question already mentions, and links to other Stack Overflow questions regarding this topic.

Previous answer, kept as a reference for future visitors who reach this page through the title, tags and question.
The backslash has to be escaped.
string = string.split("\");

In JavaScript, the backslash is used to escape special characters, such as newlines (n). If you want to use a literal backslash, a double backslash has to be used.

So, if you want to match two backslashes, four backslashes has to be used. For example,alert("\\") will show a dialog containing two backslashes.

Wednesday, June 2, 2021
answered 7 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :