Strings

by Sanju 2010-01-29 16:28:14

Strings

1) We use single quotes around strings whenever possible (e.g. strings that don't contain variables, single quotes, n, etc.). This is supposed to make less work for the PHP parser.

2) When an array variable isn't in a string, put quotes around string-literal keys so they are not regarded as constants:


// OK
echo $row[$key];

// Wrong, unless key is a constant
echo $row[key];

// Right
echo $row['key'];

// OK, since it's in a string
echo "Text: $row[key]";


3) Remember, you can break out of PHP mode for large sections of HTML. This is faster than echo'ing and you don't need to escape quotes.

Tagged in:

846
like
0
dislike
0
mail
flag

You must LOGIN to add comments