Site Meter Web Dev Notes » PHP

PHP

How to Create Websites with PHP

Sunday, May 4th, 2008

PHP Logo

Are you interested in creating a PHP powered website? Why wouldn’t you be, PHP is available for you to use absolutely free. On top of that you can make some very powerful application with PHP. Check out the following examples for instance:

Joomla - Open source content management system created with PHP
PHP-Nuke - Content Management System with phpBB built in
phpBB - Open source bulletin board system created with PHP

To learn a little more about PHP, read this Introduction to PHP page.

The following are articles I’ve written about PHP. These articles include code snippets and examples to help get you started with creating your first website with PHP. The articles cover fundamental basics which are excellent for beginners, not advanced developers. The idea is to give you all the information you will need explained when you first begin working with PHP. Once you understand the following, you’ll be able to start applying it to create all sorts of different things!


Understanding PHP and the Web Server/Browser Relationship

Your First PHP Page

How to Comment Your PHP Code

Echo vs Print - Which Should be Used?

How to Use Variables in PHP

Using Concatenation with PHP Variables

PHP Variable Naming Rules

Taking Advantage of Arrays

IF / ELSE Programming Logic

Nested IF / ELSE Conditional Statements

Introducing the Different PHP Loops

The Magic of While Loops

The Incredible FOR Loop Multitasker

The FOREACH Loop Love Affair with Mr.Array

Check back often for new tutorials!

Learn How To Fit 67 Articles Inside One

Saturday, March 22nd, 2008

Remember back in April when I became the new writer for Web Dev Notes? I started off by introducing Joomla, PHP-Nuke, phpBB and PHP. I even recommended some cool software like the ALT-Tab Replacer, Virtual Desktop Manager and the Firebug plugin for Firefox. After a slow start, I finally got my big break when my article Formatting Text in Wordpress started to bring in steady traffic!

In my early Web Dev Notes days I stuck to covering more technical topics such as how to insert CSS on your website or how to create your first PHP page. However, after testing out the use of humor in posts like the Top Ten Stupidest Joomla! Administrator Tricks and When will GoogleBot index my Brain I discovered that this unique approach was actually quite well received! I also realized website marketing and SEO was a very popular aspect of web development so I decided to venture into this area with posts like The Battle for Traffic - SEO vs Content, No Contacts, No Money and Validate Your Website for Better SEO!

Of course, even though I would later discover that marketing and SEO would be a very popular topic on my blog, at the time I had no idea yet! Looking at my stats, the posts about PHP were the most trafficked so I decided to cover this area more extensively! In May I introduced some great web development resources and then discussed the relationship between PHP and a Web Server/Browser in order to build a solid foundation before diving right into PHP for the rest of the month. I then covered how to comment PHP code, the debate over using Print or Echo, how to use variables, how to use concatenation with variables and variable naming conventions. Using this introductory material, I was then able to go even deeper and cover topics like using arrays, if/else programming logic, nested IF/ELSE conditional statements, and PHP Loops. Since the topic of loops is already an extensively covered subject, I decided to make my articles sound unique by naming them, “The magic of WHILE Loops“, “The incredible FOR Loop Multi-Tasker“, and “The FOREACH Loop Love Affair with Mr. Array“.

In order to stay informed, I subscribed to many RSS feeds relating to my topic. In so doing I noticed that Digg and Google were two very popular topics. I decided to explore these subjects a bit with articles like, “List of Google Hoaxes“, “Who’s Digging You?“, “Google’s PageRank Explained by Phil Craven“, “Declare Warr on Digg Doondles!“, “I Hacked Google and Stole Their Robot lolol“, and “Are Your Archives Burying You Worse Than Digg“. These articles continue to bring in traffic to this day!

During the month of June I was taking a course on Interface Design so decided to cover similar topics on Web Dev Notes. I began by discussing the advantages of using personas during development and then decided to list nine causes of software error before discussing software quality and the three general principles of quality assurance. I introduced the subject of human/computer interaction and demonstrated how good design can help us better interact with computers. In fact, making the interaction between humans and computers as easy as possible is an important goal of improved user interface design. I also mentioned that building the right product is even more important than building a product right.

It was around mid-June when I also began to notice how well my SEO, blogging and marketing tips posts were doing! I therefore decided to write about the guaranteed way to generate incoming links and conquering the crowded niche! I also wrote about some issues I was having with trying to follow my own advice when I noticed my trackbacks were being kidnapped and asked if it were possible if my bullets were killing them! Not wanting to stray too far from the very roots of web development, I also introduced the Pixel Groovy website, discussed how to created animated favicons and threw in 21 CSS tutorials answering frequently asked questions.

During the month of July I continued to cover a lot of marketing topics. I created a new Top 11 Posts section and asked if people thought linking to other sites increases incoming traffic. I also started to learn a great deal about blogging and realized that my very own archives contained in itself the power to help WebDevNotes succeed. I therefore stopped considering old posts like dirty socks thrown into a laundry bin, and instead began viewing them as cornerstone content that should be linked back to frequently so that new visitors could access my best content easily.

128298538306407500iminursoxst.jpg

Upon making this realization, I began offering my visitors some blogging advice with the help of Lolcats to make the posts more fun and easy to read. For example:

Don’t let Chihuahua’s hold back your website! Start working with the purrrrfect partners and plot your plan for success. Make sure you plant the seeds for success early and listen to feedback so you can feed your readers a happy meal. Make good use of article directories and other marketing techniques and never forget the secrets to writing a successful blog!

In conclusion, to those who say linking to old content is difficult, I beg to differ! Don’t let those archives go to waste ;)

FastCGI for IIS6

Tuesday, November 13th, 2007

FastCGI has been officially released for IIS6 with full Microsoft support!

Patrick Reilly writes:

Microsoft is embracing the PHP community and to help bootstrap early adopters of PHP on Windows, we’ve been validating the popular PHP applications on Windows and publishing walk-throughs that give step by step instructions on how to setup and install the most popular PHP apps on top of FastCGI and IIS/Windows.

You can download FastCGI for free at http://www.iis.net/php. FastCGI makes it possible to host PHP applications on Windows.

The FOREACH Loop Love Affair with Mr. Array

Tuesday, May 29th, 2007

Remember our good friend the array? Well one thing I forgot to mention about Mr. Array is that he is in an eternal love affair with Mrs. FOREACH Loop. I know this site is normally about web development, but some gossip about our function friends is always important. In fact, when beginning development on any new site, you should always create personnas to be representative of your users to make sure you are really addressing their needs! I’ll talk more about personas another day though, for now les get back to our lovers quarrel…!

Mrs. FOREACH Loop (yes, you need to yell FOREACH really loud, then say Loop quietly, that’s how it’s spelled and as developers we need to follow standards!) is not like our other loop friends , the incredible FOR loop and the magical WHILE loop. Mrs. FOREACH Loop does not have a statement that runs alongside a counter that continues until the statement is proven false. The FOREACH Loop continues until it has used all values contained within an array. Some might say that Mrs. FOREACH Loop is therefore a bit of a gold digger… !

It’s a pretty simple concept. If the array contains one million items, the FOREACH loop will execute one million times. Here is an example of what a FOREACH Loop looks like:

<?php
   $MrArray = array(1, 2, 3, 5, 8);
   foreach ($MrArray as $MyLove)
   {
      print $MyLove . "\n";
   }
?>

In the above example, Mrs. FOREACH Loop prints all of Mr. Arrays numbers! Don’t they make a cute couple?

If you’ve got any dirt on any other PHP functions, please do not hesitate to report your finding immediately. I’d love to get some screenshots up of Mr. Array and Mrs. FOREACH at the bar or something… :)

The incredible FOR Loop Multi-Tasker

Monday, May 28th, 2007

Let me introduce you to my little friend “For Loop”. The For Loop is a powerfull little creature for those lazy programmers who develop psychological finger cramps and constantly need shorter and shorter ways to type increasingly complex code. The For Loop comes to the rescue because it allows for everything loop related to be defined in a single line of code! The only loops that could possibly be better are the ReadMyBrain Loops possibly in development by Google?

Here is an example of the incredible For Loop in action:

<php
   for ($counter=1; $counter < = 1000; $counter++ )
   {
      print $counter . "\n";
   }
?>

The above code prints the numbers from 1 to 1000 onto the screen, each on a new line. “\n” is the newline character which forces the next print to appear on the line below.

As you can see the For Loop is a powerful creature whom can multi-task by including everything needed on a single line. It is now up to you to take this knowledge and find a more useful application for it than I have above!

The magic of WHILE Loops

Friday, May 25th, 2007

The WHILE loop is probably the most popular of the loop slaves because he is very intuitive to our needs as a programmer or web developer. Our WHILE loop keeps going while our statement which we give it to evaluate remains true. Very simple and efficient!

<?php
   $factorial = 1;
   $factorialThis = 5;
   while ($factorialThis > 0)
   {
      $factorial = factorial * factorialThis;
      $factorialThis--;
   }
?>

The code above is jibberish unless you know what a factorial is. I’ll take the assumption that if you are reading this you are at least moderately intelligent and thus will be able to figure out what it is by means of a simple example rather than a long explanation that should be read before going to bed if you wish to quickly fall asleep.

Five factorial, written commonly as 5! is equal to 5×4x3×2x1 = 120.

In the above example we compute the value of five factorial very quickly within our WHILE loop! The best part is, our code is very flexible thanks to the WHILE loop. Sure, we could have calculated the same thing using integer variables, but with the above code we can simply change the value of $factorialThis to compute the factorial of any number.

Really, this is magical and as a programmer, you must learn the spells if you hope to be a powerful wizard! Don’t tell people though that you are both a programmer and a powerfull wizard, as if you weren’t cool enough already.

Introducing the different PHP Loops

Thursday, May 24th, 2007

Loops are similar to conditional statements like if/else except that they continue to run infinitely until a certain condition is met that tells them to stop. This is very powerfull and of course potentially very problematic because their is always the risk of creating a loop which never ends and thus causes your application to stall forever. Don’t be scared though, loops are awesome! Although I do not approve of slavery, loops pretty much are slaves. You just need to tell them what to do, and they’ll get to work on it right away! You can compute hundreds of thousands of calculations in seconds because your loops will never take a coffee break.

PHP gives your three different types of slaves… err I mean loops.

Click the above links to find out more about each of the different types of loops. You’ll start to see what I meant when I said loops are extremely useful when used with arrays.

Nested IF/ELSE Conditional Statements

Wednesday, May 23rd, 2007

Yesterday I introduced If/Else Programming Logic. Today I’d like to show a more complicated example invloving nested conditional statements. What this means is that you can include If/Else statements within your If/Else statements to allow for even more complex programming logic.

Let’s look back at the example from yesterday but make it a bit more complex using nexted conditionals:

<?php
   if ($newMember)
   {
      if($uniqueUserID)
      {
         $sendWelcomeEmail = True;
      }
      else
      {
         print "User name taken";
      }
   }
   else
   {
      $sendWelcomeEmail = False;
      print "Already a member!";
   }
?>

This time, before deciding that we should send the welcome email, we add an extra if/else statement to verify that the user has selected a user name that is not already taken.

By now I am sure you are beginning to see that you will likely be using conditional statements in every program you ever write!

If/Else Programming Logic

Tuesday, May 22nd, 2007

It’s time to start introducing some more complex programming logic today! Conditional statements are still fairly simple to understand but allow for much more complex capabilities than I have demonstrated thus far. For example, while creating variables is useful, we quickly find ourselves limited in the types of applications we can make without further logic. Conditional statements allow us to include some very basic artificial intelligence into our programs by allowing the software to make certain decisions on its own based on the values of variables.

Please keep in mind that while I am demonstrating this in the context of PHP, IF/ELSE statements are a fundamental component of most programming languages.

So how does the computer make a decision? Basically, you provide a statement and then the system will verify whether that statement is true of false. Depending on the result, a different path of code will be executed. Here is an example:

<?php
   if ($newMember)
   {
      $sendWelcomeEmail = True;
   }
   else
   {
      $sendWelcomeEmail = False;
      print "Already a member!";
   }
?>

Imagine you are signing up to become a member of a website. Some function not shown will likely check the email address you provide to determine if you are already a member of the website of not. This function would then set the value of the variable $newMember to either True of False. The code above then decides if a welcome email should be sent to the user or not depending on if they are already a member of the website or not.

Again note that the function to actually send the email is not shown, but we assume that this function would take the variable $sendWelcomeEmail as a parameter and use this to determine whether or not to send the email.

Taking Advantage of Arrays

Monday, May 21st, 2007

Last week we started exploring the very basics of PHP programming. We started by first discussing the Web Server/Browser relationship, then began looking at PHP by first introducing how to comment our PHP code which is very important. We then introduced the echo and print functions, and demonstrated how to use variables and the variable naming rules. We also showed how to use concatenation.

The next step in our quest to conquer PHP is to explore arrays which are similar to variables. Arrays are used when you would like to create many variables which will be similar. Rather than create hundreds of variables, a single array could be used to store all of the related values. Each element in the array will have its own ID number which you can then use to find the desired value. For example:

<?php
   $website[0] = "www.webdevnotes.com";
   $website[1] = "www.looble.com";
   $website[2] = "www.battlecity.net";
?>

As you can see above, rather than create three different variables each containing the website URL, we instead created a single website array and stored the different website URL’s in the array. You may be asking yourself now, what is the difference between using an array like this and just using different variables? Is it just used to make the code more neat and organized? Actually, while using arrays do make the code more organized as they associate related data together, the real advantage will come when you start using loops. I’ll talk more about loops later this week.

Also, one thing to note about arrays is that it is not actually necessary to store data in an ordered fashion or to even use numerical values at all. In the above example I stored the URL’s in $website[0], $website[1], and $website[2]. You will find in many cases storing things in such a manner will be beneficial, especially when using loops. However, really, you can think of the locations where the data is saved as buckets which you can give any name you like. For example:

<?php
   $luckyNumber["Deceth"] = 11;
   $luckyNumber["Bob"] = 67;
   $luckyNumber["Harold"] = 99;
?>

Below is an example of using the above array to print Bob’s lucky number to the screen:

<?php
   print "Bob's lucky number is " . $luckyNumber["Bob"];
?>

About Web Dev Notes

Your one stop destination for anything and everything related to web development

Web Dev Notes Author(s)
    » Deceth

Blogging Flair

New Media, Web 2.0 Channel Posts

  • Podcasting Transcription
    A Guest Post from Tishia Lee of Tishia Saves Time: When I first started offering transcription services as part of my Virtual Assistant business, transcribing podcasts was not something I [...]
  • Don't Dabble - Make A Commitment
    If you want to get the best bang for your buck, plan on podcasting for the long haul. Podcasters who “test” things out with one or two podcasts and then give up may think that they've given [...]
  • A Question of Podcasting Frequency
    This follows up on yesterday's post about not dabbling in podcasting but rather to make a commitment. Podcasting on a schedule is important when building a community and an audience. Don’t have [...]
  • Do You Twitter About Your Podcast?
    Whenever I release a new episode of Work at Home Moms Talk Radio is pop the link up on my Twitter and invite my followers to come check it out. This has brought me several first time listeners which [...]
  • Looking for Podcast Outsourcing?
    I mentioned having my podcast audio's transcribed in my last post. In case you wonder - no, I do not transcribe them myself. (Shudder the thought - I did enough transcription to last a lifetime in [...]
  • Business Podcasting Benefit: Be An Industry Thought Leader
    I often ask people 'Why haven't you started your podcast yet?' and a common reply is 'I don't feel like I'm enough of an expert to cover the topic I'm interested in.' Enough of an expert? [...]
  • Business Podcasting Benefit: More Content
    Building a business on the web requires that you generate a lot of content. Content on your website draws traffic both through search engines (people searching for your content) and through links [...]
  • Business Podcasting Benefit: Deeper Relationships
    A website visitor is just a website visitor. You can't really say that you have a relationship with someone who has only visited your website can you? But when the web visitor subscribes to [...]
  • Business Podcasting Benefit: Increased Market Exposure
    When you consider how many millions of people are walking around with iPods and other Mp3 players you have to wonder, wouldn't it be awesome if they came looking for you? Well they do. Ipod [...]
  • D'ya Know Your Podcasting ABCs?
    I embarked on a fun little project this winter in which I have been working my way through the alphabet, looking for words for each letter that I could apply to the subject of podcasting. I've [...]

Hot Off The Press

  • Flip Mino
    If it is one thing you don't need when you have kids is more "things". You carry around a diaper bag, juice boxes, changes of clothes, a camera and for special occasions you bring out the [...]
  • Paris slams another report again. Yes, again!
    You read it right. If you think it’s quite odd that every now and then Paris Hilton just kept on denying issues thrown at her, then be prepared for another denial. Like somebody totally fed [...]
  • What's up for Paul Dano?
    I caught Little Miss Sunshine on cable TV early this week and wondered what's been going on with Paul Dano's career. He was touted as one of Eentertainment Weekly's successful people under 30 years [...]
  • Happy Live Show Day!
    Good Morning, Hamster Lovers! It's our first live show day! I'm so EXCITED! AGP has really stepped it up with this cast, and the two shows so far - I'm extremely pleased so far, and can only hope the [...]
  • Rihanna is stunning in yellow
    Not everybody could wear a yellow dress! That’s the sad fact I learned spending the whole day today looking for the perfect yellow dress. ‘Guess I really owe to be jealous to those who [...]
  • Testing, Testing...
    Hello all. Today I have decided to not only test out Skribit but to give you the chance to have a bit more say about the things you would like to see more of on this site. I'm going to leave this up [...]
  • Paris Hilton pregnancy rumors: Not Yet Over!
    When Paris Hilton went out with her boyfriend, Benji Madden with an alleged baby bump, everybody (at least for those who care) seems to have waited for a confirmation. However, the confirmation [...]
  • Rumer Willis needs a bra, badly!
    While I have nothing against those who feel more comfortable without a bra, I certainly think Rumer Willis case is different. Attending the Power of Paws launch party yesterday, Rumer shows [...]
  • Invalid food - or was that food for invalids?
    I'm still not well. I've finally taken a deep breath and said "I can't do all the work I want to do this week – so let me prioritise." All the rest of this week will be what I like to think [...]
  • Microsoft Copies Nintendo
    I really hate when a company tries to copy a novel and popular idea as a means of cashing it. It never works as well and usually is half assed and poorly supported. Case in point, the motion [...]