Author

TheDesignJunkie.com is the blog of Cole Hicks. Cole is a web designer, consultant, and computer book author covering topics related to graphic design, the web, and web 2.0 technology.

Newsletter

    Weekly newsletter packed full of the latest web design tips, tutorials. It's free to subscribe and you can opt-out at any time.

PHP Tutorial 7 | Working with Arrays

29 October 2007 - 9:01

Arrays are a way of storing multiple values in one variable. In essence it is a way of storing separate pieces of information (either strings or numbers) in one variable. I think of it like a shopping list. For example my shopping list contains apples, oranges and peaches. In this example I can set a variable for my shopping list ($shlst) and set build an array out of my fruit.

Arrays function by assigning a key to each value in the array. In other words, each element in the array has its own ID allowing it to be accessed appropriately.

There are three types of arrays:

  • A Numeric array - An array with a numeric ID key
  • An Associative array - An array where each ID key is associated with a value
  • And, a Multidimensional array - An array containing one or more arrays

Numeric Arrays

Going back to our shoping list variable ($shlst), lets go ahead and build a Numeric array. Well start by putting apples in our array. We’ll start by creating an array out of our apples, oranges and pears:

$shlst[0] = “Apples”;
$shlst[1] = “Oranges”;
$shlst[2] = “Peaches”;

Notice that all we did was set a variable: $shlst
assign a numerical key: [0]
and then set our value: =”apples”;

If I wanted to put that in array into a php script and have it output code I would simply do the following:

<?php
     $shlst[0] = "Apples";
     $shlst[1] = "Oranges";
     $shlst[2] = "Peaches";

echo "Shopping List: ".$shlst[2]." ".$shlst[0]." and ".$shlst[1]."'s";
?>

The code above will give me the following output:

Shopping List: Peaches Apples and Oranges’s

In this code we have set the numeric key manually, but it is also possible to have the key automatically assigned. To do that we would simply write the array like this:

$shlst = “Apples”, “Oranges”, “Peaches”;

Notice that in this example there is no key []. That is because it is being auto assigned and you are not setting it manually. Also notice that each piece of fruit is surrounded by its own quotes and separated by a comma.

Associative Arrays

Associative arrays allow you to associate values to a name instead of using a numeric key. It is very useful because it allows you to freely associate values that relate to each other. For example lets say we have red apples, orange oranges, and pink peaches (i know they are more orange but hey, I wanted a different color).

Let’s put these things into an array so that you can see what I am talking about.

$fruit = array("Apples"=>Red, "Oranges"=>Orange, "Peaches"=>Pink);

What we have done here is assign created an array of fruit with colors associated to each piece. If we wanted to write it in code we could do the following:

<?php
$fruit = array("apples"=>Red, "oranges"=>Orange, "peaches"=>Pink);

echo "<p>Q. What color are apples? A.".$fruit['apples']."</p>";
echo "<p>Q. What color are oranges? A.".$fruit['oranges']."</p>";
echo "<p>Q. What color are peaches? A.".$fruit['peaches']."</p>";
?>

Looking at what we have done notice that we assigned the color red to “apples” and the color orange to “oranges” and finally the color pink to “peaches”.

Mulidimensional Arrays

Multidimensional arrays are a very powerful feature of PHP. In essence, each variable or element in the main array can also be a variable or element. This allows you great flexibility. For example if you had an $apple_type array you could break that up into arrays based on an $apple_color array which then linked apple colors to their exact names.

Let’s look at how that would work. Note that in the code below I chose to create an array that automatically assigns ID keys:

<?php
$apple_type = array
  ( 

      "Green_Apples"=>
               array ( "Granny Smith" , "Golden Delicious"),

      "Red_Apples"=>
               array ( "Washington Apple" , "Paula Red")

   );

     echo "A " . $apple_type['Green_Apples'][0] .
            " is definitely not a red apple like a ".
            $apple_type['Red_Apples'][1].
            ".";

?>

Notice that we first created an array for $apple_type which we filled with two arrays for $Green_Apples and $Red_Apples. On outputting the results with the echo command we use the $apple_type[’Green_Apples’][0] to call up the final value of Granny Smith and $apple_type[’Red_Apples’][1] to call up the value Paula Red. It is important to note that the automatic key values start with zero rather than one. So, when calling up values you must take into account zero [0] as a placeholder.

The code above yields the following result:

A Granny Smith is definitely not a red apple like a PaulaRed.

[ Contunue to PHP Tutorial 8 | PHP’s Bulit in Functions ]

[ Go back to PHP Tutorial 6 | Switch Statement in PHP ]

No Comments | Tags: PHP

PHP Tutorial 6 | Switch Statements

29 October 2007 - 8:59

In PHP Tutorial 5 we discussed if -> elseif -> else statements. There is however, one more common type of conditional statement called the Switch Statement.

A Switch statement is generally used when you have a series of conditional statements and want to do comparisons quickly while cutting down on the amount of code needed for the program to make a decision.

Here is how it works. The Switch first evaluates a variable and compares it to what is called a Case. Here is an example:

    <?php

       $apple_color = Red;

       switch ($apple_color) {

       case 'Green':
               echo "Granny Smith!";
               break;

      case 'Red':
              echo "This apple is from Washington!";
              break;

      case 'Yellow':
              echo "This is not the best apple.";
              break;

     default:
            echo "No apples by color.";
      }
   ?>

A point of note is that Switch statements are more limited than if/elseif/else statements because they can only check to see if one variable is equal to another.

Notice that in the code above we are evaluating a single expression. In this example that expression is the $apple_color variable. The statement then compares that variable to each of the cases listed in an attempt to find a match. After each case, we have inserted a BREAK to cause the code to stop. This prevents the code from going on to the next case once it has found it’s match. However, if the program runs through each case and doesn’t find a match it will finish by outputting the default statement.

[ Continue to PHP Tutorial 7 | Working with Arrays in PHP ]

[ Go Back to PHP Tutorial 5 | Conditional If/Else Statements and Operators in PHP ]

No Comments | Tags: PHP

PHP Tutorial 5 | Conditional Statemens (If -> Else) and Operators

29 October 2007 - 8:58

Conditional statements are a way of saying, “hey, if the following criteria is met, then do this”. In PHP this happens through through two types of statements “If/Else Statements” and “ElseIf Statements”.

condition is true, execute this code;

elseif (condition)
next elseif condition is true, execute this code;

else
condition is false, execute this code;

Now, let’s use this in an example. Let’s imagine we have two colors of apples: red, and green. We want to set a variable for a color and then do a series of If/Elseif/Else statements to return the type of apple it is.

<?php
$color = "Red";

  if ($color == "Green")

        echo "This is a Granny Smith"; 

  elseif ($Color == "Red")

        echo "This is from Washington!"; 

  else

        echo "This isn't an apple!";
?>

As you can see the $color variable is set to “Red”. I used what is known as a comparative operator “==” to examine whether or not the statement was true or not. In this case if $color is equal to green (if ($color == “Green”)) we get the answer “This is Granny Smith!” returned. If $color is equal to red ((elseif ($color == “red”)) we get “This is from Washington!”.

As a result of our code we know that the $color variable is equal to red so, as a result we get the following:

This is from Washington!

If we set the color variable to “Green” we get:

This is a Granny Smith!

And, if we set it to “Blue” or some other color we would not get a match and would end up with:

This is not an apple!

Okay, so now that you have an idea of how If/ElseIf/Else Statements work lets examine the various types of operators that are available for you to use.

PHP Operators

We’ve saw the Arithmetic operators in the last tutorial. So you should be somewhat familiar with how they are used in the code. In addition to arithmetic operators, there are also operators related to Assignment of values to variables, Comparison of one value or variable to another, and last there are operators that allow you to perform logical tasks. Below is a reference:

Common Arithmetic Operators

Operator Description Example Result
+ Addition $a + $b The sum of $a and $b. So, if a equals 2 and b equals 3 the result would be 5.
- Subtraction $a - $b The difference of $a minus $b. So, if a equals 3 and b equals 2 the difference is 1.
* Multiplication $a * $b $a multiplied by $b. So, if a is 2 and b is one the product is equal to 2.
/ Division $a / $b $a divided by $b. So if a is 6 and b is equal to 2 the quotent is 3.
% Modulus (division remainder) $a % $b Remainder of $a divided by $b
- Negation -$a The opposite of $a
++ Increment $a ++ Kina like counting. If $a is equal to 4, the next increment is 5.
Decrement $a – Kina like counting. If $a is equal to 4, the next decrement is 3.

Common Assignment Operators

Operator Description Example Result
= Is set to $a = $b So, $a is equal to $b. But a better way to think of this is that what is on the left gets set to what is on the right.
+= Plus Equals $a += 6 This says
to to value on the left, "add the value on the right of yourself and then set yourself to that value". In other words if $a is 3 it adds 6 to output 9. Then it says hey, now $a is set to that number instead. So $a is now equal to 9."
-= Minus Equals $a -= 2 This says to to value on the left, "minus the value on the right of yourself and then set yourself to that value". In other words if $a is 3 it subtracts 2 to output 1. Then it says, "hey, now $a is set to that number instead. So $a is now equal to 1."

Common Comparison Operators

Operator Description Example Result
== is equal to $a == $b If we set $a to 3 and $b to 3 the result would be TRUE
!= is not
equal
$a != $b If we set
$a to 3 and $b to 3 the result would be FALSE
> is greater than $a > $b If we set
$a to 3 and $b to 1 the result would be TRUE
< is less than $a < $b If we set
$a to 3 and $b to 1 the result would be FALSE
>= is greater than or equal to $a >= $b If we set
$a to 3 and $b to 1 the result would be TRUE
<= is less than or equal to $a <= $b If we set
$a to 3 and $b to 1 the result would be FALSE

Common Logical Operators

Operator Description Example Result
&& and $a < 9
&& $b > 2
If we set $a to 4 and $b to 5 the result would be TRUE
|| or $a==3 ||
$b==3
If we set $a to 4 and $b to 5 the result would be FALSE
! not !( $a == $b ) If we set $a to 4 and $b to 5 the result would be TRUE

[ Continue on to PHP Tutorial 6 | Switch Statements in PHP ]

[ Go back to PHP Tutorial 4 | Working with Numbers and Arithmetic Operators in PHP ]

No Comments | Tags: PHP

PHP Tutorial 4 | Working With Numbers and Arithmetic Operators

29 October 2007 - 8:57

Number type variables are similar to String type variables in that whatever variable you set is equal to something. For example the variable $my_number can be equal to some number. Lets say 7. The code for such a scenario would look like this:

<?php
$my_number = 7;
?>

Notice that there is one major difference between working with numbers and working with strings. When working with numbers you do not place quotes around the value. If you did decide to place quotes around the value (in this case, the number 7), you would no longer have a number type variable. Instead, you would have a string type variable. In other words your computer would not interpret the number as a number, it would interpret it as a word (or string of text characters).

Arithmetic Operators

Now, lets do some math. In PHP, just like your elementary math courses, you can add, subtract, multiply, and divide. The opperators for these are:

+        Addition
-        Subtraction
*        Multiplication
/         Division

In addition there are a few other cool opperators that you may not know:

%       Modulus
++      Increment
--       Decrement

The Modulus operation finds the remainder of division of one number by another (wikipedia has a great explanation of how it can be used). Look at the following example:

<?php

$my_number = 7;
echo ($my_number)%2;

?>

Notice that I’ve entered a value or 7 for the variable $my_number and then said modulo by 2. Because the Modulus operator gives the remainder of the division 7 by 2 the answer is:

1

Now, if you change it to 7%5 the answer would be 2. Got it? good.

Increment and decrement operators are also very useful and work in a similar way. For example lets look at the following:

<?php
$my_number = 7;
echo ($my_number)++;

?>

In this case I’m setting $my_number variable to the number 7 and asking it to go up by an increment. Essentially I am saying count up one. The output for this is:

8

Built-in Mathematical Functions

PHP also has a number of built in functions to make your life easier when working with numbers. The most common of which is the round() function.

Here is an example:

<?php
$my_number = 2.453;
echo(round ($my_number));
?>

As you can see, in this example I am rounding off the number. The result is:

2

You can also use this function to round to a specific decimal place. lets say we want to round to two decimal places out. In that case we would use the following code:

<?php
$my_number = 2.453;
echo(round ($my_number, 2));
?>

Notice I added a comma, a space, and the number 2 after the variable $my_number inside the round function. This will yield the following output:

2.45

another couple cool mathematical function the min() and the max() functions. The min() function takes two numbers, compares them and outputs the lower of the two. The max() function takes two numbers, compares them and then outputs the higher of the two. Lets take 5 and 7 for example. Using the max() function, the code would look something like this:

<?php
$my_high_number = 7;
$my_low_number = 5;
echo(max ($my_high_number,$my_low_number));
?>

Notice I set two variables for my numbers. One is a high number, and the other is a low number. They are equal to 7 and 5. As you can imagine, using the max() function the code returns the higher value of the two generating the following result:

7

The last function that I’m going to show you isn’t really mathematical, but it is most appropriate that you learn it here. The function is the number_format() function. The cool thing about this function is that it takes a number, like 1967 and styles it. So the number 1967 comes out like 1,967. In essence, it groups the numbers and puts a comma where it needs to be. Here is an example:

<?php
$my_number = 1967;
echo(number_format ($my_number));
?>

Notice that I didn’t put a comma in my number. Yet it comes out like this:

1,967

[ Continue to PHP Tutorial 5 | Conditionals in PHP ]

[ Go back to PHP Tutorial 3 | working with Strings and Numbers in PHP ]

No Comments | Tags: PHP

PHP Tutorial 3 | Working With Strings

29 October 2007 - 8:56

In the PHP Tutorial 2 | PHP Variables we covered the basics of what variables are. In doing so we also introduced strings.

What are strings?

Strings are simply a grouping of characters that PHP relates to a variable. This grouping can be a bunch of letters like “ABCDE” or it can be a word like “Hello” or it can be a combination of numbers and letters and other types of punctuation like “tutorial_3 on PHP”.

To demonstrate lets assign the strings “Granny Smith” and “Green” to the variables $apple_type and $color:

$apple_type = ‘Granny Smith’;
$color = ‘Green’;

Putting them into our PHP script along with the echo () function, would look like this:

     <?php

        $apple_type = 'Granny Smith';
        $color = 'Green';

        echo $apple_type;
        echo $color;
      ?>

Notice that we placed “echo $apple_type;” and “echo $color;” on separate lines. Looking at our file through a web browser we’ll see that even though they are on separate lines the print one right after the other:

Granny SmithGreen

A better way to write this code is to concatenate the strings and add the formatting we need at the same time.

Concatenating Strings

Concatenating strings is performed using the period (.)

In our code, to concatenate the two variables we simply place the period in between the variables we want to concatenate. Here’s an example:

<?php

$apple_type = ‘Granny Smith’;
$color = ‘Green’;

echo $apple_type.$color;
?>

This will result in the following to be printed on screen:

Granny SmithGreen

As you can see we still need to add some additional formatting. And, by concatenating some formatting into things we can. Here’s how:

<?php

$apple_type = ‘Granny Smith’;
$color = ‘Green’;

echo $apple_type.’ ’.$color;
?>

Notice that I added ‘ ’ to the code will result in the following:

Granny Smith Green

String Specific Functions

In PHP, there are several functions that you should be familiar with. I’ll cover just a few here to give you an idea of some of the built in possibilities.

strlen() — counts how many characters your string contains. Here is an example Lets count how many characters we have in the $apple_type string we created above. Here’s how that looks:

<?php

$apple_type = ‘Granny Smith’;
$color = ‘Green’;

echo strlen ($apple_type);
?>

Looking at the results we get:

12

Another useful one is chunk_split(). As the name implies, this function splits a string into a number of smaller chunks. The syntax is as follows: chunk_split(string,length,end)

Here’s an example of how it works:

<?php
$apple_type = “Granny Smith”;
echo chunk_split($apple_type,1,”-”);
?>

Notice that we split the words Granny Smith ($apple_type) at a specific interval (1), and we told the function to end each split with a dash (”-”). Here is what the output looks like:

G-r-a-n-n-y- -S-m-i-t-h-

The last one we’ll cover in this section is str_replace(). This function simply replaces part of a string with something else. It follows a specific syntax:
str_replace(find,replace,string,count)

Here is an example of how it works:

<?php
$apples =”Granny Smith apples are red.”
echo str_replace(”red”,”green”,$apples);
?>

Notice that I created a string “Granny Smith apples are red.” Using str_replace() I am able to replace the word red with the word green giving me the following result:

Granny Smith apples are green.

[ Continue to PHP Tutorial 4 | Working With Numbers and Arithmetic Operators in PHP ]

[ Go back to PHP Tutorial 2 | Variables in PHP ]

No Comments | Tags: PHP

PHP Tutorial 2 | PHP Variables

29 October 2007 - 8:54

So what are variables? Think of it like math. In algebra the letter “x” is usually equal to some number. X is the variable. In effect, X is a way of storing some type of number. In PHP variable’s act in a similar way. Variables are simply a way of storing values like text strings, numbers or arrays.

Variable Syntax

Variables must be written in a specific way for PHP to know what they are. There are six basic rules:

  1. A variable’s name always starts with a dollar sign ($).
  2. A variable can be made up of a combination of strings, numbers and underscores.
  3. Variable names are case sensitive (unlike functions) so the variable $VariableName is not the same as $variablename
  4. Variables are assigned values using the equals sign (=)
  5. A variable name can not contain spaces. Rather than using a space you should separate words with an underscore.
  6. The first character after the dollar sign can’t be a number.

Here are some examples of valid variable names:

$apple
$apple_name
$_apple

Notice that each of the variables start with a dollar sign and their first letter is either a regular letter from the alphabet, or an underscore.

Now, to drill it in your head lets take a look at a few invalid variable names:

$2apples
$apple colors
$+

Of the three names each are invalid. The first because it starts with a number, the second because it contains space, and the third is because it is not a letter of the alphabet or an underscore.

Now that you understand the syntax let’s go ahead and create a variable in a php script. We’ll continue on with the script we created in the PHP Basic Syntax Tutorial:

<html>
      <head>
      <title>PHP Tutorial</title>
      </head>
<body>

     <?php
        echo "My first PHP script!";
      ?>

</body>
</html>

In this code we’ll add a string variable. It is called a string variable because the variable is equal to some character string. In this case, a string of text:

$scriptname = “Script Number 2″;

Adding this to our code we get the following:

<html>
      <head>
      <title>PHP Tutorial</title>
      </head>
<body>

      <?php
        $scriptname = "Script Number 2";
        echo "My first PHP script!";
      ?>

</body>
</html>

You have now created a $scriptname variable. It is important to once again note that variable names are case sensitive. So the variable
$scriptname is different from $ScriptName, and that is different from $SCRIPTNAME. As a newbie to scripting it is common to accidentally capitalize a variable and then spend hours wondering “what happend?” Simply taking the time to check for these types of mistakes will save you hours of frustration.

Okay, so that we can see this variable do something let’s add it to the echo() function and remove the line “My first PHP script”. Our new PHP script looks like this:

     <?php
        $scriptname = "Script Number 2";
        echo $scriptname;
      ?>

Notice that we first set our $scriptname variable equal to something. In this case it is equal to the text string Script Number 2. After we set the variable, we then called it up in the echo function. It is important to understand the value in this. By setting a variable, we are able to set the variable one time and use it where ever we like by calling it up.

Loading our code to our server and looking at it in a web browser we get the following:

PHP Tutorial 2 | PHP Variables

[ Continue to PHP Tutorial 3 | Working With Strings ]

[ Go back to PHP Tutorial 1 | Basic PHP Syntax ]

2 Comments | Tags: PHP

Three Rules for Business in a Web 2.0 World

28 October 2007 - 21:44

It happens to the best companies out there. One day while checking into their e-commerce revenue, site traffic, newsletter subscriptions, and Google rankings something seems amiss. Things have been chugging along for years but suddenly the revenue is down, or the site traffic is a little off, or the number of people subscribing seems to be dropping off.

The problems are very minor at first and companies typically rely on their web team and marketing department to resolve them. But, no one seems to know just what the issues are? That is because traditional marketing does not take into account the three rules of doing business in a web 2.0 world.

Web 2.0 Rule #1 What the Community Wants, the Community Gets

But, you ask, what does that mean? Let’s look a quick example.

PlanetOut.com (www.planetout.com)

Way back when I worked for them (it was a fun company to work for at the time) they were building a small empire that relied heavily on revenue generated from subscriptions to personal add services in addition revenue generated from advertising and sponsorship. They also made some headway in the travel and destination side of things. It was a good business model for the time and worked well for them until about 2005. Now the company is nearly defunct. It’s stock has hit an all time low and things don’t look good for the company.

What happened?

From the outside it is pretty clear what happened. MySpace and FaceBook, along with a host of other social networking sites changed the rules. Suddenly the community wanted to be able to claim their friends and meet people through their own acquaintances. They wanted more interaction on their profile pages than PlanetOut was willing to give, and more importantly, they didn’t want to think of their “social networking” as hooking up through a personal ad.

What could they have done? Way back in 2005 when they noticed things were dropping off they had an opportunity. It would have had to have been drastic, but the opportunity was there none the less. At this time, PlanetOut knew something was wrong. MySpace was on the rise and their own membership was flat. At this point a company has a couple options. Re-design your own website so that you can more effectively compete by adding the social networking services that your competition has, or purchase your competition.

In 2005 I would venture to say that PlanetOut didn’t need to compete head to head with MySpace, but they did need to answer the community’s call for social networking services, the likes of which only MySpace and a few others were providing at the time.

In effect, the wave of technological innovation that began way back in 2003 created new ways of doing business which we are now calling web 2.0.

In addition to sites that rely on revenue from personals adds like PlanetOut and Match.com there are a number of other sites which may soon be in trouble. Like who you ask? One example are sites which provide photography services. For example a site like Snapfish which relies on revenue generated from photo printing services is at an extreme disadvantage to a site like Flickr. Let’s look at them side by side and see why.

Snapfish vs. Flickr

It is true that for the moment Snapfish is a profitable company and they have done very well, but web 2.0 changes everything. Here is the core of the issue. Snapfish is clearly focused extracting revenue by touting value for their customers. Glancing at their hompage makes this clear. Their homepage reads:


“Welcome to the best value in photography”

Now, there is nothing inherently wrong with extracting revenue. All business needs to generate revenue, but they are missing the big picture. And unfortunately for Snapfish, Flickr has their eye on it. Glancing at their home page you’ll notice a very different message:

“Share your photos. Watch the world”.

So what is the danger to Snapfish? Snapfish is breaking rule #2 for doing business in a web 2.0 world.


Rule #2 Enabling Community Comes Before Revenue

Just looking at the two home pages gives you an insight that many inside Snapfish will fail to see. Snapfish is not moving quickly enough into the world of web 2.0. They are still putting revenue before community while Flickr is focused on creating a community first, then extracting revenue. Both companies have a similar revenue model. They sell photo services to their customers. The advantage that Flickr has at the moment is that they are doing a much better job of enabling the community to live through their photographic experiences. What this means is that if Snapfish does not change its focus so that it puts community first, they will soon be left wondering where their market went? The answer won’t be surprising; their market will be hanging out on Flickr.

What’s worse is that, at the moment, I’m sure the folks over at Snapfish believe that they are focused on community. But looking at what they say tells another story. Just check out their “about us page” where they say:

“Snapfish is a leading online photo service with more than 40 million members and one billion unique photos stored online. We enable our members to share, print and store their most important photo memories at the lowest prices.”

Most people would say that this proves they are developing community and committed to web 2.0 but this is not the case. I’d read this differently. From the statement above I’d say they are committed to building a leading online photo service and happen to have a community as a result. There only mention of interacting with other members comes down to a line about sharing their photos. This shows a lack of dedication to rule #2 because community is not the first priority; instead they are focused on revenue.

Finally, in the battle between Flickr and Snapfish there is one more clear advantage that Flickr has. That is, that its members create content that other users want. It isn’t just sharing with your friends and loved ones. It is sharing and creating content with the world at large for free, and without the need for registration. This leads to rule #3.

Rule #3 Community Builds and Manages Itself

But wait you say, Snapfish members are free to upload and do what they want right? Wrong, Snapfish members are simply using a tool for organization and management and sale of their existing photos. Those members are not managing other members, building community tools, creating their own content to be shared across the network, or developing Snapfish interfaces. On flickr they are. Community members police their own user generated content, they build application interfaces and mashups to allow their flickr content to appear on their blogs and on their own personal websites. And the folks at flickr enable organic community growth. The flickr team is focused on enabling their community to be as creative and self managing as is possible with their flickr accounts. This is an area where snapfish fails miserably.

But don’t think that Snapfish is the only one with an issue. Snapfish is just one example of a good company facing challenges. There are a host of very solid companies that will need to address the same type of issues.

Apple and iTunes

Apple iTunes is also breaking the rules. Don’t get me wrong, it is a great application and right now is the industry norm, but it is only a matter of time before another company pops up and takes a real bite.

By selling downloadable music with digital rights management (DRM) encrypting Apple is faced with a conundrum. Users don’t want DRM. Unfortunately for Apple most of the music industry does. This has left Apple calling for an end to DRM, but not actually being able to completely break free of it. Amazon and a host of other music services have latched on to this opportunity and are now launching music downloading services which are DRM free. But this is not the only area where Apple could face a challenge. What happens when a site or application pops up that provides open, DRM free music and video downloads? What happens when that site focuses on enabling the community to experience and truly share music with the world? But let’s take this one step further, what happens when those users are enabled to mash existing music tracks and share their creations for free online? Where do you think all of the iTunes users will be hanging out?

Summary

As you can see the rules apply to all companies operating online. Some, like PlanetOut, have been hit early and are already feeling the effects. Some, like Snapfish, are just now beginning to notice that something is happening. And others, like Apple with its iTunes music store have not yet been hit. The one thing we can all be sure of however is that the rules are there, and companies will live and die by of them.

No Comments | Tags: Online Strategy, web 2.0

Finding From the Web Design Survey (web developer market research)

27 October 2007 - 21:40

In April 2007, A List Apart and An Event Apart conducted a survey of people who make websites. It is an amazing amount of work. Close to 33,000 web professionals and junkies alike answered the survey’s 37 questions, providing valuable data related to the business of web design and development as practiced in the U.S. and worldwide.

What is more intriguing is that they have made the data available for free from their website. Here is the link to download the survey findings from A List Apart:


A List Apart, Web Design Survey
.

Even better for those of us addicted to crunching numbers, they have made the actual data available for free as well. This is a true testament to the spirit of an open and free web, and I’m very impressed and thankful for their hard work.

So, what can we find out about our fellow Web Junkies in the report?

Well, it looks like we are mostly a white men around 30 with a bachelor’s degree and we like to be called either web designer’s or developers, most of us have blogs.

I also liked seeing that people in this field over the long haul tend to see their salary increase, “From Fig. 3.4, it is clear that the longer respondents are in the field, the more they earn.”

I was shocked to see that there are not more women in the field? For those that are in the field there is some positive info in there about the “Gender Divide”. You know, that divide that generally has men making much more than women for comparable jobs. Here is what the survey says about that:

Fig. 3.5 examines earnings and gender. While overall earnings are comparable, a greater percentage of men than women take home under $20,000. On the flip side, a greater percentage of men than women make more than $80,000; the same is true for earnings of more than $100,000.

Last, I had to chuckle when I saw the information related to “job satisfaction by age group”. The younger we are, the less satisfied we are with our jobs. I think that is true for most of us when we are/were young. The older you get, the more you are able to leverage your experience to get the job you want. In contrast, when you are young you are much more likely to take the job you can get.

Anyway, download the report for yourself and have a look. It is always good to understand how the marketing guys view you ;-)

1 Comment | Tags: Web Design

PHP Tutorial 1 | Basic PHP Syntax

27 October 2007 - 21:37

The structure of PHP code is fairly similar to other programming languages such as Perl and C. Although PHP is a scripting language and not a programming language, if you understand how to program with C or Perl you should have no problem picking up PHP. For those of you just starting out, don’t worry these tutorials will show you everything you need to know to get started.

PHP Structure

Basic PHP scripting always starts with <?php and ends with ?>. Some servers work with an informal or shorthand version allowing you to start a scripting block with <? and end with ?&gt. In your (x)HTML page it would look something like this.

<?php

[some type of PHP code here]

?>

Within the scripting block is were the meat of the script goes. It contains things PHP statements that are made up of things like functions, variables. In PHP it is important to note that some things, like functions are case sensitive, while other things like variables are case insensitive. As we go along I’ll point these out so that they become more obvious.

Constructing a PHP statement

To construct a statement we need to create the code that tells PHP to do something. To demonstrate let’s look at one of the most common functions you will come across in PHP, the built in Echo() function (I call it the echo() function as do most people even though if you want to get technical– it is a language construct).

To build a statement with Echo() we would write the statement in between our <?php opening and our ?> ending. We close the statement with a semicolon like this:

echo “My first PHP script!”;

Alternatively you could also write the statement with parenthesis like this:

echo (”My first PHP script!”);

Or, if you like more white space you could write it like this:

echo (

“My first PHP script!”

);

As you can see PHP is very flexible. White space is not an issue and there are many ways to write a statement. Additionally, although the above statement contains only one simple command telling the browser to print a string of text, it is important to note that statements can become very complicated. As you progress you will learn how to construct statements that perform things like comparisons and loops — I know, it’s very exciting!

To make a basic PHP script

To make a basic PHP script all you need is a text editor. I like to use either programmer’s notepad or BBEdit. But you can also use Notepad or TextEdit.

Start by opening a new file and creating a basic HTML document. In side that document we’ll place our basic PHP script block so you can see how it works. Something like:

<html>
      <head>
      <title>PHP Tutorial</title>
      </head>
<body>

     <?php
        echo "My first PHP script!";
      ?>

</body>
</html>

Here are a few things to notice.

First the PHP script opens with our opening command:

<?php

Once the script is open we wrote our statement:

echo “My first PHP script!”;

We wrote the statement in a very common way, enclosing the string of text within a pair of quotation marks and ending the statement with a semicolon. Finally we closed our statement with our closing command:

?>

Saving the file it is important to save it with the extension .php rather than .txt or .html. This is how the server knows that the page contains a PHP script. Once you save the file, we’ll call it PHPscript.php we’ll need to upload it to a web server to view it. Once uploaded, we’ll call the page up in a web browser. Doing so you should see the following:

php script #1

About The Echo () Function

In this script we are using the “echo” function; When writing about functions for technical documentation they are generally written function() with two parenthesis. The parenthesis indicate to the reader that they are looking at a function. So the echo function is generally written:

echo ()

I’m sure you have noticed that echo() is a method of printing something. A similar function that you can use is the “print” function; generally written:

print ()

So, in our code we could have written either:

echo “My first PHP script!”;

or:

print “My first PHP script!”;

Once again, it is important to note that PHP is not case sensitive when it comes to functions or language constructs. So:

Echo (”My first PHP script!”);

Works just the same as:

ECHO (”My first PHP script!”);

Also, while we are on the subject, an important difference between echo() and print() is that with echo() you can send multiple words using commas. An example looks like:

echo “My”,”first”,”script!”;

This is not possible using print(). Last, once again notice how the echo function ends with a semi-colon (;). The semicolon is used to distinguish one set of instructions from another. In essence, it is what separates one command from the next. Each command must end with a semicolon. What that means is that if you wanted to print two commands you simply need to separate statements with semicolons like this:

echo “My”,”first”,”script!”;
print ” It’s a simple echo function!”;

Comments in PHP

Every good web designer comments their scripts and fortunately for us in PHP there are several methods to do so. The first, and probably the most popular method is to use two forward slashes like this:

//

When PHP encounteres two forward slashes it interprets everything on the line after the slashes as a comment. There is no need for a semicolon here to end the comment.

Another method for commenting is to use a hash mark:

#

It works just like the double forward slashes.

Last, if we want to add a large comment block we use a forward slash and an asterisk to open the block:

/*

And an asterisk followed by a forward slash to close the comment block:

*/

Here are some examples:

// Below this one line comment is the echo function

echo “My first PHP script!”;

Notice that I placed the single line comment above the echo function. Alternatively I could also write the comment like this:

echo “My first PHP script!”; //this is the echo function

I put this comment off to the right. Like I stated previously, everything after the two forward slashes is interpreted as a comment on that line. I could also write this using the hash sign:

echo “My first PHP script!”; #this is the echo function

Or like this:

#####################
#Below is the echo function
#####################
echo “My first PHP script!”;

Last, is the comment block written like this:

/*
This is a block comment. The text
that I enter can be put on a bunch
of lines. Below is my echo function.
*/
echo “My first PHP script!”;

[ Continue to PHP Tutorial 2 | PHP Variables ]

No Comments | Tags: PHP

Photoshop Tip #3, Create a Text Bounding Box

26 October 2007 - 3:32

There are times when you want your text to fit within a selected area. This is when it is a good idea to create a text bounding box. To create one simply select your text tool, click and drag across your image to create the box and type away.

text bounding box, photoshop tip

No Comments | Tags: Photoshop