We'll begin right at the top, with some very basic definitions and concepts. In PHP, the term "string" refers to a sequence of characters. The following are all valid examples of strings: String values can be assigned to a variable using the standard assignment operator. String values may be enclosed in either double quotes ("") or single quotes('') - the following variable assignments are equivalent" String values enclosed in double quotes are automatically parsed for variable names; if variable names are found, they are automatically replaced with the appropriate variable value. PHP also allows you to create strings which span multiple lines. The original formatting of the string, including newlines and whitespace, is retained when such a string is printed. The <<< symbol indicates to PHP that what comes next is a multi-line block of text, and should be printed as is right up to the marker "EOF". In PHP-lingo, this is known as "here document" syntax, and it comes in very handy when you need to output a chunk of HTML code, or any other multi-line string. Strings can be concatenated with the string concatenation operator, represented by a period(.) Note that if your string contains quotes, carriage returns or backslashes, it's necessary to escape these special characters with a backslash. The print() function is used to output a string or string variable. PHP also offers the echo() construct, which does the same thing. Since displaying variable values is one of the most fundamental things you can do, PHP also offers a shortcut syntax (similar to that offered by JSP) to simplify this task. The following two statements are equivalent:
blog comments powered by Disqus |