Web Development News, Tips, Insights | Website Magazine

Essential PHP Tips & Resources

Written by Peter Devereaux | Jun 4, 2011 5:00:00 AM

The World Wide Web has evolved from static readonly pages to the amazingly complex dynamic websites of the Web 2.0 era.

In large part, this has been made possible by scripting languages such as PHP which, over the past few years, has become the most popular method for building interactive websites.

PHP operates from a server to interpret data and execute functions, then sends the results to the user's browser. Like any programming tool, there are standard protocols that must be learned before achieving mastery of PHP. One of the greatest resources available to beginners is the PHP Manual; that starts with a basic tutorial then moves along step-by-step to much more advanced operations.

Environment

There are thousands of things one can do to make life easier while using PHP. Installing and configuring the proper tools is a good place to begin. There are many more available than what can be listed here, but a few essentials are:

- An Integrated Development Environment (IDE) - An IDE is an editing tool that provides color-coded syntax highlighting, an interpreter, tools for build automation and a debugger. Some also include an FTP feature. There are many packages available. Some are geared to handle multiple languages with prices ranging from free to several hundred dollars.

- While in the creation stages, turn on error reporting. It will help to find those pesky bugs that, while do not keep the code from running, produce inaccurate data. However, once everything is functioning accurately, don't forget to turn error reporting off.

- Install WAMP (Windows) or MAMP (Mac) on your local computer to test your MySQL database interactions. - Keep up with PHP upgrades. The gurus are constantly working to make the language more efficient and secure. Older versions might cause performance issues.

Best Practices

Clean, logical code runs smoothly and is easier to edit. While many "best practices" can limit your efficiency, there are some standards that apply to any language, including PHP.

- Separate code into three logical divisions; such as the input interface, the validation tier, and the database communication tier. Called three-tier architecture, this structure keeps each layer separated into its own section so that changes can be made to one without altering the others.

- Always use standard syntax. Shortcuts won't save that much space or time and may cause headaches later if they are deprecated.

- Name variables and functions with clear and consistent formats to make editing easier for yourself and others.

- Make frequent comments within the code to explain the developments at each point.

- Declare variables and functions outside of loop code. The more operations that the loop must perform, the longer it will take for each iteration to complete.

- Avoid redundant database queries. Combining queries as much as possible will speed up processes.

Code Snippets

There are many repositories of small utilities that perform common tasks and help to make efforts to produce dynamic results more efficient. Publicly available snippets, such as these, can save long hours of work.

- Display different images based on the day of the week with this little gem:

 

- Automatically change the appearance of your page based on the day of the week by inserting this into your header:



Then add the following to the section of your page you want to alter:

 

- Supply daily quotes that reflect your philosophy with a simple script. Simply create an array and fill it with your sources.

 

- Changing the appearance of the page is fun, but code snippets can also do more useful things such as creating a random password.



PHP can be used to create dynamic content that reflects your visitor's interests and tastes to make them more comfortable on your website and encourage them to return - including a feeling of security, which PHP can be used to authenticate and verify input data.


About the Author: Brian Flores is a SEO and copywriter for InMotion Hosting, one of the top dedicated server providers in the country. He works with a team of awesome writers to post useful tutorials on WebHostingHelpGuy. You can follow him on Twitter @WHHG_InMotion or @BrianAFlores.