1 on 1 web hosting - PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY There
Wednesday, October 24th, 2007PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY There are two ways around this problem: Use double quotes if the text includes any apostrophes. Precede apostrophes with a backslash (this is known as escaping). So, either of the following is acceptable: $book[’description’] = “This is David’s sixth book on PHP.”; $book[’description’] = ‘This is David’s sixth book on PHP.’; The same applies with double quotes in a double-quoted string (although with the rules reversed). The following code causes a problem: $play = “Shakespeare’s “Macbeth”"; In this case the apostrophe is fine, because it doesn t conflict with the double quotes, but the opening quotes in front of Macbeth bring the string to a premature end. To solve the problem, either of the following is acceptable: $play = ‘Shakespeare’s “Macbeth”‘; $play = “Shakespeare’s “Macbeth”"; In the first example, the entire string has been enclosed in single quotes. This gets around the problem of the double quotes surrounding Macbeth, but introduces the need to escape the apostrophe in Shakespeare s. The apostrophe presents no problem in a double-quoted string, but the double quotes around Macbeth both need to be escaped. So, to summarize: Single quotes and apostrophes are fine inside a double-quoted string. Double quotes are fine inside a single-quoted string. Anything else must be escaped with a backslash. The key is to remember that the outermost quotes must match. There is more on this important subject in the second half of this chapter, including a technique that avoids the need to give special treatment to quotes. Special cases: true, false, and null Although text should be enclosed in quotes, three special cases true, false, and null should never be enclosed in quotes unless you want to treat them as genuine text (or strings). The first two mean what you would expect; the last one, null, means nothing or no value. Technically speaking, true and false are Boolean values. The name comes from a nineteenth-century mathematician, George Boole, who devised a system of logical oper- ations that subsequently became the basis of much modern-day computing. It s a com- plicated subject, but you can find out more at http://en.wikipedia.org/wiki/ Boolean_logic. For most people, it s sufficient to know that Boolean means trueor false.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.