PHP: Playing With Arrays

Here’s a “Learn by Example” type of entry for php arrays. I tried to comment as much as I can, but like always, please ask if there’s something you don’t understand. I also want to note, you have to run the script to see that my comments are telling you the truth.

Read the rest of this entry »

3 Comments

Guide: To Validate or Not Validate HTML?

Benefits of Validation (x)HTML

There are several DTD (Document Type Declaration) that can be used (and should be used) when coding a website. W3 has a validation page (and there are other tools that can also do this) to check that your code is clean.

No one is going to police you if your (x)html does not validate. It gives you a bragging right (if anyone cares)? I suppose so.

I will be honest and say that I do not always validate my code unless requested by my clients. However, I would like to point out some key benefits for validating:

1. Expanding your audience

This will allow impaired individuals (vision, motor, cognitive or otherwise) to use their devices on your site.

2. Expand to a wider range of devices

Technology is ever growing. Perhaps one day, companies will learn the web standards and display it the right way without today’s differences in IE vs. Firefox (or any other browser).

3. Search Engine Friendliness

Clean code enables the spiders to crawl your page more efficiently.

4. Faster Loading

Without HTML errors, your browser can load the page and thus, reduce the wait time for your visitors.

5. Easier to maintain website

Even if you have no mistakes, perhaps it’s a syntax or hack, having clean code (and well indented code) will make it easier for you to update your site to keep your content fresh.

1 Comment

Guide: Perserverance Overcomes All

When you’re writing for a website, a lot of times, you want your hard work to pay off right away. You want to see the traffic and you want to see people interacting with your website, whatever it may be.

I have learned through the years that you have to stick it out through thick and thin. You won’t get the traffic you want to see right away and that’s where a lot of people give up, delete what they have (or just abandon it entirely).

Here’s a few pointers to help get you going, without the cost of paying for a service to put ads on their sites to help you out.

1) Leverage social media.

There is nothing better than using word of mouth nowadays. People love to gossip, they love to tell about what resources they used to make money or to learn something. When someone asks for help, the first sentence is usually “Oh here’s a good site to read about that” and then chucks up a link.

This isn’t to blatantly say, “Use your friends to power your website” but it is really just to say, hey, your friends can help you power your website. People you meet online, can power your website. So utilize your facebook, myspace, twitter, and other social networking to promote your site.

2) Have substance before opening up your site to the public

If you only have 1 or 2 articles down, where is the interest going to spark? Have 5 or 6. Give your visitors browsing material, give them something to draw them in.

3) Don’t paste adsense all over the place.

I have adsense on this blog but you only see it one designated area. Don’t turn your blog into “advertisement galore” too soon. I honestly don’t ever plan on doing that with any site I launch. Having ads is okay but it’s very apparent to the user when you’re offering real content and when you’re just trying to get a dime off their time.

4) Steal but don’t steal.

Find your own niche and your own drive. Write something you’re interested in and something that you can create original content for. Make sure you have a voice for the website you want to create vs. creating a website because it happens to be the “next big thing” in the blogosphere.

5) Update your site regularly.

When we go to Yahoo and look for news, we expect news to be on there and not the same articles headlining the day before. Visitors to your site expect the same thing. Make your subject broad and expandable so that you have a variety of aspects to pick from.

If you have any further advice on sticking out the thick of thin times when developing a website, please leave a comment and let people (along as myself) know!

No Comments

PHP: A Fast Way to Print Alphabet

Here is… something that most will say “What!? How useless.”

But I just think it’s funny. :) There has to be some fun in what we do, right? So here is a snippet to print out the alphabet, first in uppercase and then in lowercase. :)

1
2
3
4
5
6
7
8
9
10
<?php 
 
for ($i=65; $i<=90; $i++) { 
	$x = chr($i); echo $x; 
} 
 
for ($i=97; $i<=122; $i++) { 
	$x = chr($i); echo $x; 
} 
?>

4 Comments

PHP: The Switch Statement

The switch statement can save you a lot of lines of coding. It can pretty much be used with any datatype (as far as I know). Check out my quick coding sample!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
 
//check the value of a number and print something out
$value = 1;
 
switch ($value) {
case 1:
	echo "1";
	break; //break says when to stop executing commands for this parameter
case 2: 
	echo "2";
	break; // see, you need it after every parameter
default: //default happens when no case matches the parameters
	echo "No number";
}
 
//switch statements can also be used with strings
$string = "This is a dog.";
 
switch ($string) {
case "This is a dog.":
	echo "Dog";
	break;
case "This is a cat.";
	echo "Cat";
	break;
}
 
//and number comparisons
$number = 100;
 
switch($number) {
case $number <= 50:
	echo "This number is less than or equal to 50";
	break;
case $number >= 50;
	echo "This number is greater than or equal to 50";
	break;
}
 
//arrays?
$items = array();
$items[] = "dog";
$items[] = "cat";
$items[] = "lizard";
 
foreach ($items as $itemValue) {
 
	//lets check to see what's on the list
	switch($itemValue) {
	case "lizard":
		echo "Lizard!";
		break;
	case "dog":
		echo "Dog!";
		break;
	case "iguana":
		echo "Iguana!";
		break;
	}
}
?>

3 Comments

PHP: A Few Math Functions

Math is fun in PHP when you need to do some calculations. Here’s a few functions that are pretty fun for me to play around with. However, don’t forget you can also achieve simple operations as well.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
 
//echo pi
echo "Pi = " . pi() . "<br />";
 
//sin, cos, tangent
echo "Sin of 1 = " . sin(1) . "<br />";
echo "Cos of 1 = " . cos(1) . "<br />";
echo "Tan of 1 = " . tan(1) . "<br />";
 
//Rounding Up
echo "Rounded up, 5.923423423 = " . ceil('5.923423423') . "<br />";
 
//Rounding Down
echo "Rounded down, 5.234234243 = " . floor('5.234234243') . "<br />";
 
//Taking numbers to the x power
echo "53<sup>3</sup> = " . pow(53,3) . "<br />";
 
//Choosing a random number
echo rand(1,100)
?>

1 Comment

PHP: A Quick Rundown of the Basics

There is nothing better for me than to learn by example. However, that’s also how I teach best, is by example. I wrote this quick rundown of the basics of PHP. Commentary in comments. :)

Read the rest of this entry »

No Comments

Intro To Java: Integer Division

Here goes another Intro To Java entry. I would like to clarify that I’m no pro at Java. I write about this to share the buck I paid for taking a college course on it (and hey, having my notes somewhere I can’t spill my drink on, right on!). Please feel free to contribute to this discussion and/or my education if I miss out on any important points.

Today’s topic is “Integer Division.”

Let me try and start from the ground up here. There are 6 data types.
1. byte
2. short
3. int
4. long
5. float
6. double

This entry is discussing the arithmetic operater, division and the data type, int (short for integer).

The division operation requires special attention when it comes to integers. In most cases, 1 divided by 2 is 0.5. However, when dealing with integer data types, the answer is simply 0. Why? When integers are divided by integers (hence the “integer division”), it will truncate any decimal value and leave it as a whole number (don’t confuse this with rounding).

No Comments

Web Development Resources

I wanted to point out a few resources to give more of a starting point, even if I plan on writing more tutorials. If you have any to contribute, please leave a comment. I’d be interested in seeing what others have come upon! :) It can be anything related to web development/design.

Overall
Webmonkey
Resources for Web Design
Dev Listing

HTML/CSS
CSS-Tricks
CSS Basics
CSS Cheat Sheet
W3’s Markup Guide
HTML Center

PHP
PHP.net

No Comments

PHP: Search and Replace [Example]

Here’s a quick php tutorial on how you can build a tool similar to what I use at work. Basically, it’s a search and replace tool using the str_replace(). I know in PHP 5, this may have changed but at the time of building the tool, I was using PHP 4.

The Problem
At work, I have to use <p> tags a lot. I’m more lazy than your average duck when it comes to redundant work. I know that the Dreamweaver keyboard shortcut for wrapping <p> tags is ctrl+shift+p. But even that is too much to do when I have more than say.. 5 paragraphs. Again, lazier than your average duck.

The Solution
I really like building my own tools. I really like PHP. I really want to learn more. Yes, despite writing this blog and giving out tutorials, I still don’t know it all. Most of my experience is from playing with fire a.k.a. trial and error. So, one morning when I had no tasks at hand, I sat down and wrote this small program. Basically a large textarea to paste stuff into, click submit, and out comes <p&gt tagged paragraphs!

Much better than pushing a shortcut 5 times, in my opinion!

Read the rest of this entry »

3 Comments