Presenting Emerald and Apologizes

July 30th, 2008

Emerald CMS is no longer, sorry

First off, let me start with my apologizes for everyone not being able to post a reply or send in a request. I didn’t notice when someone tried to do either of the two that they were actually being sent to PayPal instead. This mistake was fix with the help from Shaun emailing me directly to notify me of the issue. I don’t want anyone to pay me to reply to a post or send in a tutorial request, I greatly appreciate any comments. That “Pay Me” button is for donations and clients only.

Again, sorry for that. So please fill free to reply or request away.

Now on to Emerarld CMS.

Emerald CMS at this point in time isn’t a CMS. As of now, its several files which you could download at look through, and its based of one of my recent tutorials, Basic File Structure, at the mean time. What I imagine Emerald to be, is not just an opened source CMS, but an open minded CMS where developers can share their ideas, advice, thoughts, opinions, code, and help into making it a CMS which they feel comfortable to use for their client work. I hope the programmers look toward the Emerald CMS as a kick start for their work to get all their sites going at first and only make a few adjustments to fit their, or clients, needs. I also imagine it being used by non-code heads for their shopping cart site, or a large message forum, or schedule management, etc.

Again, these are just my visions with Emerald, I am not set on it being one or the other or both. Right now, I do hope it turns out to be useful for both coders and non-coders.

Blog > Website


July 24th, 2008

When dealing with forms its very important to validate what the user entered so you don’t get false email address, phone number, zip code, etc. There are multiple ways to validate what the user entered in the input field of your form(s). The way I suggest and I am going to share with you is through Javascript. I wrote a nifty little function called validate which takes the two required parameters, the first being what you want validate, and the second is the value or string to validate/test it with. Here is the function:

function validate(what,str) {
if(what == “email”) {
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
return filter.test(str);
} else if(what == “phone”) {
// (123) 456-7890
var filter = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;
return filter.test(str);
} else if(what == “num”) {
// must be a number, or can’t be zero
if((str / str) == 1 && str != 0) { return true; }
else { return false; }
} else if(what == “zip”) {
// 12345 or 12345-1234
var filter = /\d{5}(-\d{4})?/;
return filter.test(str);
} else if(what == “date”) {
var filter = /^([1-9]|0[1-9]|1[012])\D([1-9]|0[1-9]|[12][0-9]|3[01])\D(19[0-9][0-9]|20[0-9][0-9])$/;
return filter.test(str);
} else if(what == “url”) {
// or
var filter = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
return filter.test(str);
} else if(what == “ext”) {
// personally, I only accept images with jpg/jpeg, gif, or png format. But this can anything to your liking
str = str.toLowerCase();
if(str.lastIndexOf(“.jpg”) == -1 && str.lastIndexOf(“.jpeg”) == -1 && str.lastIndexOf(“.gif”) == -1 && str.lastIndexOf(“.png”) == -1) { return false; }
else { return true; }

This function does a lot different validating and testing, and of course this can continue to grow to your pleasing. As of now, the function is set up to return either true or false. I suggest keeping it this way if you plan adding or changing some of the regular expression checking. This is how to use the function:

// get the phone value from the form
var phone = document.forms[0].phone.value;

// validate the phone number
if(!validate(“phone”,phone)) {
alert(“Invalid Phone Number entered”);

If the phone number is invalid, then it will do an alert telling the user that they didn’t enter the correct syntax for the phone number. If it was entered correctly then it was entered correctly and javascript will continue with the rest of the script.

I hope you find this useful. Enjoy!

Javascript > Website

Basic File Structure

July 7th, 2008

A lot of times when I do work for companies, or freelance work, I really stress the importance of good file structuring so programmers, and non-programmers, know the flow of the web site. I am sure there are a few of you rolling your eyes already thinking this is a waste saying, “I already know how to do this”, but then there are some saying, “This is great, just what I need to help me get started in web site developing”. This article is for that audience. However, some of you who already know how to structure a web site could learn something new.

A lot of you might structure the web site like so:

  • index.php
  • db_access.php
  • footer.php
  • header.php
  • images
    • (all the images)
  • style.css


  • index.php
  • include
    • db_access.php
    • footer.php
    • header.php
    • style.css
  • images
    • (all the images)

If you are new to web site development, the first structure is most likely your method, placing all your files in the root directory without knowing the importance or hierarchy of the files and folders. The second method is approached more often once you become more experienced and start organizing your files and folders. These two methods are fine and expected, but I would like to share with you how I organize my files and folders so maybe you can start learning at a more quicker pace. This is how I structure my web sites:

  • assets
    • assets.php
    • css
      • (all css files)
    • images
      • (all image files)
    • js
      • (all javascript files)
    • php
      • (all php files)
  • index.php
  • layout.php

I have a directory called “assets” (of course you can call this “include” if you wish), and within that assets directory I have more directories that correspond to what that specific file/extension belongs to. So CSS files go in the “css” directory, PHP classes and functions go in the “php” directory, etc. My “assets.php” file keeps track of all my main and global variables. For example, I like to create a variable called $DR (short for Document Root), which acts like a fake document root, yet works just like a document root. This is very helpful for when trying to place an image on the page. Instead of having to guess how many directories I have to think back, I can just do this:



I could just type / instead of ../../../../, but again, I use the $DR as a fake document root because maybe I have the site in separate directory. Ok, lets get back on track, apologizes for straying a bit. In my assets.php file, I could also use PHP’s build in function session_start() so I don’t have to keep typing it every time, and have it connect to my MySQL database, etc.

Well, that is all I have to share with my Basic File Structure. Please let me know how you structure your websites, I would love to hear some tips and tricks from your experience. Thanks


Add/Remove Directories

June 4th, 2008

I just wanted to share with you 2 small, yet very useful, functions that you could use in PHP: dir_create and dir_remove. The name of the function gives away the purpose of what they will do. From time to time, I will get stuck with “Why is PHP not creating the directory?” or “Why isn’t PHP removing the directory completely?”, and that is where these two functions come into play to help you with those pesky little simple questions. Here are the functions:

Read the rest of this entry »

PHP > Website


May 31st, 2008

DomReady has been starting to become all the craze lately with the language Javascript to use for HTML pages. But what is it? DomReady allows you manipulate with all the elements on the HTML page before the entire page loads. What use can this be if you can just use window.onload instead? Well, imagine a large site like, or, which have a lot of flashy banner ads and images to load. My guess for the entire page to load can take ~10 seconds, assuming we are on a fast connection speed to the Internet, respectively. That isn’t bad, most of us can wait 10 seconds for a page to load if it’s our favorite site to visit. But for some users who don’t have a high speed Internet, they will have to wait a lot longer for the page to load, and therefore the Javascript window.onload function won’t be executed until it takes it sweet time to load.

Read the rest of this entry »

Javascript > Website