1.

What is the meaning of ‘escaping to PHP’?

Answer»

The PHP parsing engine needs a way to differentiate PHP code from other page elements. The mechanism to achieve this is KNOWN as ‘escaping to PHP’. Escaping a STRING means REDUCING ambiguity in quotes used in that string.

For example, when you’re defining a string, you surround it in either double quotes or single quotes:
"HELLO, InterviewBit." 

But what if I include double quotes within the string?
"Hello "InterviewBit."" 

Now I have ambiguity - the interpreter doesn’t know where does my string end. If I want to KEEP my double quotes, I have various options. I could use single quotes around my string:
'Hello "InterviewBit."' 

Or I can escape my quotes:
"Hello \"InterviewBit.\"" 

Any quote that is preceded by a slash is escaped and understood to be part of the value of the string.



Discussion

No Comment Found