are there any other tricks such as includes and the mail function that will be of use to me in the future? thanks for reading. eddie.
Tricks? Millions...whether they are useful to anyone other than you is the more important question...
Don't write code only you will understand...even if you are the only one who will *ever* work on it...the logic is simple...if someone finds it difficult to comprehend your code...chances are so will you when you leave something and come back to in 6 months time.
Learn as many best practices as you can...confirm them for your self...unfortunately this takes years of experience as you cannot possibly make many mistakes in a single day...
Time and experience is the only trick I know of thats truly undisputable...everything else is subjective but I won't start that debate again.
Here are some cool "tricks":
1. Instead of using
Code: Select all
if($a == $b){
echo 'Me';
}
else{
echo 'You';
}
While this is typically prefered construct when writing code...when writing templates with tons of HTML it sometimes helps to use the ternary operator and do the same thing in one line of code:
2. Alternate row colors using a simple binary trick as opposed to manually testing for odd or even row numbers
Code: Select all
$bgcolor = ($count & 1 ? '#FFEEFF' : '#EEFFEE');
3. Use PHP alternative syntax when writing code in your templates...I hate seeingstandard syntax in anything but pure PHP class files, modules, etc
4. Don't use double quoted strings unless you actually have a need for it...
5. Validate everything, use proper escaping routines, filter any non-essentials charactcers and lastly use htmlentities() when echo'ing to your templates to avoid embarising XSS exploits.