5 Things I wish I had known about PHP
Written by Bean on April 13, 2009 – 3:19 amLike most independent geeks, I started off by teaching myself PHP. I already knew Java, PERL, BASIC and ASP so many things about PHP were easy for me to learn. I rolled up my sleeves and went to work coding interactive PHP web sites. I drank gallons of caffeine and cruised the PHP forums at all hours of the night, seeking answers to my PHP questions. I could have saved a lot of time, energy and sleep if I had been taught these five things about PHP.
1) Code first, style second
The code is the backbone and structure to your web site. Code your PHP, HTML and JavaScript before you dress up your pages. Make you code clean, make it solid and make it ugly. It is much easier to debug and validate your code without the styling. Once you have the basic structure in place and functioning, start adding your styles. If your styling is dynamic, for example a style sheet determined by a user selection, add in your logic
2) Follow separations of concerns standards
Separations of concerns means segmenting your code so the HTML, the PHP and the styling are kept separate. At the top of your document, place as much of your documentation and scripts as you can. Make it as easy as possible to find your variables and code. Use linked CSS style sheets instead of embedded code. Finding that missing semicolon is hard enough in reading through 30 lines of code. Sorting through 80 lines of code with tags scattered throughout is a nightmare that I lived through way too many times.
Go a step further, once you have got your custom PHP functions operating smoothly, place those functions in include files with excellent documentation. This makes your code more modular and easy to reuse.
3) Well documented code saves time
OK, I had this drummed into my head in college, but that was for school, not for real life, right? Boy was I wrong! The first time I had to upgrade my code after two month intermission, I was saying all sorts of naughty words. The blue language and my foul mood could have been easily eliminated if I had documented my all of my PHP variable declarations, my loops and my functions.
4) Creating a mail form is easy, creating a secure mail form not so easy
The PHP mail function looks easy but looks are deceiving. Mail is a spammers’ gold mine and they spend a lot of time and energy trying to get your mail functions to work for them. It takes diligence to stay on top of their tricks. I have learned that using a current 3rd party script, from a reliable source, is the way to go. I don’t have the time or the intelligence to keep up with the spammers so I rely on those that do and keep my mail forms secure.
5) DOCUMENT _ROOT is your friend
I am a big fan of includes. When Vikki taught me about includes and SHTML here at LVS Online long ago, I was ecstatic! It made much more sense to me than templates but I struggled with paths. How could I make my footer include work in my home directory and my nested directories. My navigation includes kept me up way too late at night. I am embarassed that my first PHP sites would have include folders for each level of directory and yes I would edit two levels of includes and forget to edit the third ARRRRGH.
The PHP superglobal server variables were something I didn’t discover until over 6 months into my PHP ventures. $_SERVER["DOCUMENT_ROOT"] solves all of your include and multiple directory issues.
Tags: Documentation, DOCUMENT_ROOT, Separation of concerns, Superglobal variables
Posted in PHP | 1 Comment »
Learn MySQL/PHP and support Australian bush fire victims
Written by Bean on February 10, 2009 – 5:46 pmThe death toll from the bush fires in Australia is 181 and counting, but you can help. Sitepoint, an Australian web designcompany, is offering a huge sale on their excellent books. You can buy five books for the price of one and 100% of the proceeds will go to benefit the brush fire victims. The sale goes through 2/13 so you will want to take advantage of this offer quickly. The loss of home and livelihood has been staggering and the Australian brush victims are in desperate need of assistance now.
Here are some books that I think may be of particular interest for MySQL and PHP students:
The PHP Anthology: 101 Essential Tips, Tricks & Hacks, 2nd Edition
Build Your Own Database Driven Website Using PHP & MySQL
HTML Utopia: Designing Without Tables Using CSS, 2nd Edition
The CSS Anthology: 101 Essential Tips, Tricks & Hacks, 2nd Edition
Build Your Own Web Site The Right Way Using HTML & CSS
The Principles of Beautiful Web Design
Once you have selected your books, be sure to use the form here to get the sale pricing and to make sure that all proceeds go to the brush fire victims.
Tags: Books, MySQL, PHP
Posted in Reference | No Comments »
New PHP Study Group
Written by Bean on January 6, 2009 – 7:26 pmLVS students have banded together to create a new PHP study group. This PHP study group is LVS students and alumni that want to help each other in their PHP pursuits. They are beginning with PHP for the World Wide Web, Second Edition (Visual QuickStart Guide) which is an excellent beginning PHP text.
You can join the PHP study group at Hello World. Kudos to Bonnie and Joanne for taking the initiative to get this going!
Tags: PHP, Study group
Posted in PHP | 4 Comments »
Intro to MySQL – Jan 08
Written by Bean on January 3, 2009 – 7:26 pmIntroduction to Database Development with MySQL – get organized for the new year. Databases are a great way to organize all kind of data from your books to your products to your contacts. In this course, you will use special database accounts on the LVS server to create an address database. We will be using MySQL 4 for this course. Anita will be the assistant this session.
LVS Online MySQL database class starts on 1/10/09. Register now!
Tags: Classes, MySQL
Posted in Class Announcements, MySQL | No Comments »
PHP for Web Developers course starts soon
Written by Bean on January 3, 2009 – 8:43 amIts not too late to register for PHP 101 for Web Developers at LVS Online!
Learn how to use PHP4 or PHP5 to make your web site more dynamic and interactive. Utilize PHP to automate some of the more mundane tasks of your web site and prevent errors, all while creating a standards compliant web site.
We have changed the staffing of this course to provide a cooperative learning experience. This session of PHP 101 for Web Developers will have an assistant, an instructor and a back up instructor to help guide you through the assignments.
The online PHP classroom opens on Monday and the first lesson will be posted on 1/10/09. Registration ends soon!
Tags: Classes, PHP, PHP4, PHP5
Posted in Class Announcements, PHP | 2 Comments »
Attention LVS Students!
Written by Bean on October 1, 2008 – 12:44 amTell us who you are and which class(es) you are enrolled in this session. Let us know how LVS classes has affected your life in your professional field and/or in your personal life. Which ones have been your favorites? We enjoy hearing of your experiences. Thanks for sharing with LVS staff, fellow LVS students and our blog visitors!
If you’d like to view other students experiences at LVS Online Classes, visit the main LVS Blog and click the Blogroll links.
Tags: LVS Online
Posted in Class Announcements | 11 Comments »
How does PHP compare to Ruby on Rails, Django, Python etc?
Written by Bean on September 26, 2008 – 7:38 pmThis question came up recently on the PHP class boards about scripts and frameworks such as Ruby, Django, Python, CakePHP and Symfony. I thought that it was worthy of some discussion here and moved the thread to the blog.
How does PHP compare to other server side languages? I’ve been reading up on it a bit, and it seems like some developers are quite antagonistic toward PHP, in favor of Django, Python, Ruby, Symfony, etc. instead. Do you favor PHP with MySQL? What do you think of Ruby on Rails or the other various combinations? I’m interested in developing web apps and am not sure where I should focus my attention. I’m new to all of this.
First, we need to make the distinction between scripting languages and frameworks. Frameworks are language specific tools that assist you in creating web applications, in particular database driven web sites. Pylons gives a good description of the components of frameworks.
- something that generates HTML
- something that reads arguments that are sent via HTTP
- something that communicates with your database
- something that contains your application logic
- something that deals with user accounts
- something that stores persistent data (like cookie-based sessions)
The big benefit to frameworks is that they come with libraries of frequently used code components that can save you hours in development time. Instead of writing something from scratch and debugging, you can pop in components and just customize arguments.
PHP frameworks include: Symfony, Zend, CakePHP, and CodeIgniter
Ruby framework is Rails
Python frameworks include: Django, Pylon, Turbogears
To utilize these frameworks, you will want to have at least a basic knowledge of the underlying scripting language. Ruby has been getting a lot of attention because it is object oriented and PHP has just recently entered the objected oriented programming (OOP) arena. Of the three, I think Python has the steepest learning curve for the base language but I have to admit that I haven’t played with it in at least two years. I think that Ruby could give PHP some competition down the road but not immediately. I see Python and Ruby being relegated to the geek corner for awhile, while PHP continues to be the predominant scripting language.
Why PHP?
- it is already installed on most web servers and works great with the most popular web server in the world, Apache. Ruby and Python often require separate installations and can be intimidating.
- PHP is widely available on inexpensive hosting plans. Since Ruby and Python usually require additional installations, web hosting accounts with these languages installed tend to be more expensive.
- Although all three languages have rich frameworks available to them, for every 10 shopping cart, forum, blog, content management, mailing list applications based on PHP you will find one or less based on Python or Ruby. It is much easier to add PHP applications to your project because you have so many choices.
- Since there are many more trained PHP developers than Python and/or Ruby developers available, PHP web applications tend to less expensive to maintain.
- Although PHP 4 was at a disadvantage, PHP 5 and 6 have greatly improved object oriented programming capabilities that challenge Python and Ruby. Although Ruby still exceeds in this regard, it is more complicated to install on a Linux system and retain all of the flexibility of the language and framework. It has a dramatically reduced number of applications to interact with as well.
This is just a brief summary of the languages and frameworks. There is considerable debate and programmers can become rabid fans of THEIR language/framework. I don’t believe there is just one answer to which is the best. I do believe that PHP is the language to start with in terms of its learning curve, its widespread use and availability, its power and scalability and the sheer demand for PHP programmers. There is an interesting blog post and discussion at Killersites that reenforces some of the arguments that we present here.
Once you have decided which language to pursue, you can start testing out frameworks. They all have their strengths and weaknesses. If you google them, you will find fans and detractors for all of them. You really need to test them out and see what matches your needs and workstyle. Other times your place of business will determine which framework they want to use. Frameworks do not necessarily play nicely with each other. As time allows we will try to post some reviews of specific frameworks. Check back later.
We welcome your thoughts and comments on this debate.
Tags: OOP, PHP5, Zend
Posted in PHP | 4 Comments »
PHP Random Image Generator: Arrays and numbers oh my!
Written by Bean on September 13, 2008 – 5:21 amIn the second week of the PHP 101 for Web Developers course, we introduce arrays through a Random Image Generator. One of things that confuse students most about arrays is how they count. You are probably really used to starting counting with the number 1. When working with arrays, you have to learn how to count from 0!
Arrays store information in a very precise order. At home, you might keep your household bills in a file box organized by month. If you want to know how much your electric bill was last March, you would look in your folder labeled March, the third folder. That assumes you store your bills by month and by year. What about if you stored your monthly bill folders in alphabetical order. It wouldn’t matter as long as you know where to look.
Arrays aren’t as lax about organization as we might be. PHP arrays always Read more »
Tags: Arrays, Images, PHP, Random Image Generator
Posted in PHP | 1 Comment »
Intro to MySQL databases: Question Week 2
Written by Bean on September 6, 2008 – 8:33 amThis week, the introduction to MySQL students have been looking at various database schemes as well as their own address database. Databases are everywhere in our lives these days. Think of things in your own life that are powered by databases, that are NOT web related. In the intermediate course we turn our attention to data driven web sites. But the first couple of weeks in the introduction course, I want you to think of databases on a larger stage. Post two things in your life that are database driven and give a description of at least one table that might exist in that database.
For example: My doctors’ office tracks all appointments in their database. I would imagine that it has a table that contains information about the individual doctors, as well as a table that contains specific information about individual patients. My neighborhood video store has a database that lists all of the movies at that store. The movie table probably lists things like title, genre and year released.
You don’t need to give a lot of detail. Just list two examples and for each example try to guess how at least one of those tables might organize information
Posted in Class Announcements | 6 Comments »
Google released their Windows browser: Chrome
Written by jeramie on September 3, 2008 – 5:44 amTags: chrome, google, google chrome, new browser
Posted in Class Announcements | 3 Comments »

