How to quote in echo or print in PHP?

If you are creating applications in PHP, even if you are beginner, you definatelly see echo function already. Echo function just outputs it's argument to a user browser or to a console/terminal if PHP script is running in the CLI mode. The trouble rises, when you have to put ' or " sign in a echo, because you have to use one of this characters just to begin and terminate echo literal. To embed such characters in displayer string, you need to use escape sequence. It is a special characters combination, that makes some special sense in string literal. So, if you want to send quote sign to user, not to terminate echo string, use \" escape sequence. If your sequence is terminated by single quotes ('), then you can also include this character in string by escape sequence \'. See examples below:echo "This example shows \"escape sequences\" in php string, like quotes etc"; echo 'This example shows \'escape sequences\' in php string, like quotes etc';You can be confused if you think, what to do to put a slash in php string (\), because it has some special meaning. But I have solution for you: this character also have some custom escape sequence, and this sequence is: "\\".

Comments

Popular posts from this blog

How to construct a B+ tree with example

How to show only month and year fields in android Date-picker?

Visitor Counter Script Using PHP