Latest Posts »
Latest Comments »
Popular Posts »

5 Things I wish I had known about PHP

Written by Bean on April 13, 2009 – 3:19 am

Like 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: , , ,
Posted in PHP | 1 Comment »

New PHP Study Group

Written by Bean on January 6, 2009 – 7:26 pm

LVS 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: ,
Posted in PHP | 4 Comments »

PHP for Web Developers course starts soon

Written by Bean on January 3, 2009 – 8:43 am

Its 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: , , ,
Posted in Class Announcements, PHP | 2 Comments »

How does PHP compare to Ruby on Rails, Django, Python etc?

Written by Bean on September 26, 2008 – 7:38 pm

This 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: , ,
Posted in PHP | 4 Comments »

PHP Random Image Generator: Arrays and numbers oh my!

Written by Bean on September 13, 2008 – 5:21 am

In 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: , , ,
Posted in PHP | 1 Comment »

Geeks: Boring? They are creative masters!

Written by Bean on August 12, 2008 – 4:56 am

Geeks get a bad rep. Depicted as nerdy dorks, their creativity is often overlooked. I was delighted to come across this blog post  at LifeDev that focused on the creativity and imagination that is unleashed with code.

Working with code is one of the most creative jobs one can have. Programmers have to balance two very different worlds: a world of structure and a world of imagination. They create abstract concepts using very structured programming languages (like PHP or Java).

The author goes on to outline 14 steps to creativity inspired by programmers.

  1. Learn a new language
  2. Start from the ground up
  3. Question everything
  4. Do it for fun
  5. Never stop testing ideas
  6. Find a passion
  7. Master your tools
  8. Start making abstract associations
  9. Think of structure as a tool, not a limitation
  10. Don’t rule anything out until you try it
  11. Always look for a simpler and more elegant solution
  12. Don’t be afraid to build off the code of others
  13. Don’t be afraid to collaborate
  14. From the basic, create the beautiful

You can read Glen’s description of these 14 lessons in his blog post but I was struck by how many of his lessons we try to incorporate in to our “geeky” courses here at LVS Online. Every week or so, I will tackle one of those lessons in geek creativity here in this blog. You can start with the first lesson, “Learn a new lesson” by signing up for the PHP For Web Developers 101 course!


Tags: , ,
Posted in PHP | No Comments »

PHP Date Formats

Written by Bean on August 10, 2008 – 11:14 pm

The table below shows the characters that may be used in the format string.

Each character represents a part of the formatting.

Date Characters
Character Description
a “am” or “pm”
A “AM” or “PM”
B Swatch Internet time (000-999)
d Day of the month with a leading zero (01-31)
D Three characters that represents the day of the week (Mon-Sun)
F The full name of the month (January-December)
g The hour in 12-hour format without a leading zero (1-12)
G The hour in 24-hour format without a leading zero (0-23)
h The hour in 12-hour format with a leading zero (01-12)
H The hour in 24-hour format with a leading zero (00-23)
i The minutes with a leading zero (00-59)
I “1″ if the date is in daylights savings time, otherwise “0″
j Day of the month without a leading zero (1-31)
l The full name of the day (Monday-Sunday)
L “1″ if the year is a leap year, otherwise “0″
m The month as a number, with a leading zero (01-12)
M Three letters that represents the name of the month (Jan-Dec)
n The month as a number without a leading zero (1-12)
O The difference to Greenwich time (GMT) in hours
r An RFC 822 formatted date (e.g. “Tue, 10 Apr 2005 18:34:07 +0300″)
s The seconds with a leading zero (00-59)
S The English ordinal suffix for the day of the month (st, nd, rd orth)
t The number of days in the given month (28-31)
T The local time zone (e.g. “GMT”)
U The number of seconds since the Unix Epoch (January 1 1970 00:00:00GMT)
w The day of the week as a number (0-6, 0=Sunday)
W ISO-8601 week number of year, weeks starting on Monday
Y The year as a 4-digit number (e.g. 2003)
y The year as a 2-digit number (e.g. 03)
z The day of the year as a number (0-366)

Tags: , , ,
Posted in PHP, Reference | No Comments »

Registration is open for PHP & MySQL

Written by Bean on August 1, 2008 – 12:01 am

September registration is now open at LVS Online Classes! Classrooms will open on Aug. 25, 2008. Registration ends on Aug. 27, 2008. The first lesson will post on Aug. 30, 2008.

September Session Offerings:

New! Now PHP4 & PHP5
Introduction to PHP for Web Developers

MySQL4 & PHP4
Introduction to Databases with MySQL
Intermediate Databases with MySQL & PHP


Tags:
Posted in Class Announcements, MySQL, PHP | No Comments »

Introduction to php: php 101

Written by Bean on May 7, 2008 – 4:37 pm

In this class we will focus on using PHP with the Apache Web server on Linux. This class will take designing web sites to a higher level. We will learn how to make your user’s experience more personalized, how to reduce the time it takes to create large websites, and how to download and customize open source scripts. Here is a brief list of what will be covered:
  • Integrate PHP with HTML
  • Including files
  • Variables
  • Conditional Statements (if-then)
  • Looping (for-next)
  • Managing files on the server
  • Uploading images
  • Mailform
  • Cookies
  • Customizing downloaded scripts

You will be required to have a hosting account that supports PHP web pages. If you do not have a web site with PHP installed on the server, as an option you can install it on your own computer, however there will be very limited support for this method and you will have no way to post assignments for them to be reviewed. Downloads and information for installing PHP and Apache on your computer can be found at the following web sites:
Download PHP for free here: http://www.php.net/downloads.php
Download Apache for free here: http://www.php.net/manual/en/installation.php

To test whether your web hosting account provides support for PHP, you can download and extract this file test-php.zip and upload it to your server. If your server supports PHP, it should return to you a page listing the PHP configuration on the server. If you are installing PHP and Apache on your own computer, use one of the following links to access this file:

http://localhost/test.php
http://127.0.0.1/test.php

You can register for this course at http://www.lvsassociates.com/register/product_info.php?products_id=136


Tags: ,
Posted in Class Announcements, PHP | No Comments »
Programming Blogs - BlogCatalog Blog Directory