Asked  9 Months ago    Answers:  5   Viewed   41 times

Can anyone tell me what is happening here?

<?php
// true
var_dump('\ ' === ' ');

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

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

 Answers

90

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 '\\ ';   -> \ 

See http://php.net/manual/en/language.types.string.php#language.types.string.syntax.single.

Wednesday, March 31, 2021
 
binoculars
answered 9 Months ago
63

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
 
millenomi
answered 9 Months ago
100

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

http://net.tutsplus.com/articles/news/codeigniter-from-scratch-day-1/

Wednesday, March 31, 2021
 
alioygur
answered 9 Months ago
16

$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
 
ranhan
answered 7 Months ago
45

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
 
muaddhib
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 :
 
Share