Home Yellow Pages Movies Classifieds Jokes Jobs Free Hosting Videos




PHP Coding Tips

undefined variables

Single or Double Quotes - 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.

Quotes in Array - 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]"; 

Do Not echo Large HTML code - You can break out of PHP mode for outputing large sections of HTML. This is faster than echo'ing and you don't need to escape quotes.

Large Strings

$string = <<<ENDOFSTRING
This is a string
It can include both 'single' and "double" quotes 
without needing to escape them. However, $variables
will still be interpolated as they are in double 
quoted strings. Complex variable expressions such as
{$array['element']} or {$object->property} can also
be included and will be evaluated if they are included
in curly braces (they may work without curly braces
but I tend to include them for added clarity). The
string will terminate with whatever you specified
at the start like this:
ENDOFSTRING; 

Make sure "ENDOFSTRING;" should be in first column, if tab or space before start of ENDOFSTRING;, it will not work.

Read more about strings at http://in.php.net/manual/en/language.types.string.php


BizHat.com   Bookmark   Astrology   Chat Room   Classifieds   Computer   Downloads   Directory   Dating   Domain Tools   Education   eCards   Finance   Forums   Freelance Work   Free Hosting   Free Mail   Gallery   Games   Guest Book   Greeting Cards   Ham Radio   Health   Home Business   Hosting Tutorials   Hosting Directory   India   Jobs   Jokes   Kerala   Matrimonial   Music   Movies   News   News Letter   Recipes   Real Estate   Search   SMS   Tourist Guide   Top 100 Sites   Vote Us   Yellow Pages   Arthunkal Church   Site Map  

Google