Currently Browsing: Home » 2009 » September

Archive for September, 2009

How to Quickly Apply Many PHP Functions

Let’s say that you have just created a new company and are in need of a contact form. For this form, you want to let the user provide a name, e-mail (so you can get back to them), and a message. In order to make sure you are receiving valid content, it is vital that you check and manipulate user input in order to meet your needs.

Functions

Requirements

For example, what if you wanted the message to be in a strict format, like so:

Every Word In A Sentence Must Be Capitalized. There Must Be No Html Tags And The Rest Of The Letters Have To Be Lower Case. In Addition, No Excess Whitespace Must Exist On Each End Of The String.

Read the rest of this entry »

Remembering the User’s Preferred Color Scheme

Last time, we showed you how to set up alternate color schemes using PHP. As promised, we will now show you how to remember the user’s choice.

We will once again make use of PHP, this time cookies. We will explore how to set the cookie for the user’s choice, and two methods of using this information.

First, we shall create a file. For purposes of demonstration, this file shall be called switch.php.

Read the rest of this entry »

Stunningly Simple CSS Minifier

Creating a beautiful and eye-catching website can often require you to have a hefty CSS file. Unfortunately, this side-effect takes away from your visitors experience; they spend more of their time downloading rather than viewing. In essence, a balance needs to be reached in order for full optimization.

CSS

Solving the problem

One simple way to achieve this balance is by using a minifier. By taking a CSS file in as input, a minifier removes white space and other unnecessary elements to significantly reduce file size.

Read the rest of this entry »

Alternate Color Schemes Using PHP

One great use for PHP is alternate content depending on different inputs. In this article, we will show how to serve up alternately colored style sheets via PHP.

Disclaimer: This makes use of CSS variables, over which there has been much debate. This article will not discuss whether one should or should not use CSS variables, only present a way to use them.

First, the call in the HTML will no longer call a CSS file, but a PHP file.

<link rel="stylesheet" type="text/css" file="styles.css" />

to

<link rel="stylesheet" type="text/css" file="styles.php?color=green" />

Of course, color can be any nomial you wish, and green can be any color you wish, or even the name of a color scheme, such as hotlava.

Read the rest of this entry »

Delete the First Character of a String with PHP

When it comes to any skill, reinforcing the basics can pave the way for a boundless future. Indeed, taking a step back and presenting simple topics promotes a better form of comprehension. Thus, today’s post focuses on one primordial PHP function: how to delete the first character of a string.

To accomplish this task, you should be familiar with PHP’s substr( $string, $start, [ $length ] ) function. When used with only the first two parameters, substr returns all characters in $string from index $start to strlen( $string ) - 1 (the end), inclusive. Note that the first index of a string is actually zero.

Read the rest of this entry »

« Older Entries