Posts Tagged ‘snippet’

How to Time Delay Posts in Wordpress

Saturday, March 8th, 2008

One reason I’ve heard people say that they prefer a full-blown CMS to Wordpress is that Wordpress doesn’t allow time delayed posting. I was about to figure out a way to mod Wordpress to make this possible - until I realized that there is some decent built-in functionality for time delaying.

You can easily delay the release of your posts into the main indexes (front page, archives, “Recent Posts” list, etc). With a little bit of code, you can also restrict people from viewing the page before its appointed “Published” date.
(more…)

How to Work With Directories in PHP

Thursday, March 6th, 2008

PHP offers a number of different functions to work with the local directory structure. There are at least three fairly simple ways to create and output a list of files in a directory.

Like the file functions, each method is slightly different. Knowing how each operates will help you choose which function to use when you want to work with directories in your PHP script.
(more…)

Use Javascript to Parse a Query String

Tuesday, March 4th, 2008

Most server-side scripting languages, like PHP, come with built-in functionality for reading query strings. Javascript doesn’t have any kind of standard counterpart, but that doesn’t mean you can’t use query strings in Javascript.

With some String functions, you can create your own function to parse a query string attached to the request url and store it in an associative array - just like PHP would for you.
(more…)

How to Randomize AdSense Ads with Javascript

Friday, February 29th, 2008

I came across this problem on the forums today. How can you randomize which Ad Sense ad to show using Javascript?

The solution, it turns out, is very simple.
(more…)

Javascript Function: Random Number Generator

Sunday, February 24th, 2008

Yesterday, I wrote a short article on generating random numbers in Javascript. The Javascript random number generator is similar to C/++ - it gives you a random number from 0 to 1 and you need to make it useful.

At the suggestion of a reader (thanks Justin), I decided to go ahead and turn the general formula for this into a short helper function to generate a random number.
(more…)

New Script: PHP Length Conversion Class

Sunday, February 10th, 2008

I was looking for a project to tackle today, and I decided to make a script that would convert lengths from one unit or system to another.

It doesn’t sound all that complicated - and it’s not. I had a working script in a few minutes, but I didn’t like it. It had too many functions to do conversions for individual units. I wanted this script to be pretty well abstracted so that I could easily add new unit types - and so that the source code for the class would be very short.
(more…)

How to Integrate an RSS Feed Into Your Site with Simple XML

Saturday, February 9th, 2008

Practically every site today has an RSS feed. Now, you could be like everyone else and simply use this as a way to read information as it’s published.

Or, you could use RSS for what’s intended for - content syndication. With Simple XML, it’s a piece of cake to use an RSS feed to add a list of links to relevant articles on your page.
(more…)

How to Create a Random Date in PHP

Thursday, February 7th, 2008

While browsing some forums the other day, I came across this question - “How do I find a random date in PHP?”

This is a pretty simple operation, if we make use of a few built-in PHP functions - time(), strtotime(), and date(). In this article, we’ll see how these three can work together to find a random date within a given range.
(more…)

How to Create a Random Password for Users

Friday, February 1st, 2008

If you’re working on a user-management system, you may find it useful to be able to create a random password for users.

Some systems generate these initially and have the user log in to set a permanent password. You might also have a “Reset” button, where the script generates a random password and e-mails it to the user.

This quick tutorial will show you how to create an 8 character random password containing a mix of letters and numbers. Or, if you’re impatient, jump straight to the function’s source code
(more…)

How to Pass All Elements of a Form to the End in a Multi-Page Form

Sunday, January 27th, 2008

Sometimes forms get long, unsightly, and intimidating. It’d be great if you could cut them up into three or four parts - with a few fields on each page.

In order to do that, you need to figure out some way of storing or passing along the information from the first pages. I’ve heard a bunch of crazy ideas - from storing the information in session variables to writing each part to the database.

The easiest thing to do is attach a very brief php function to the bottom of each page. It’ll do all the work for you and continue to post every item the user has entered. (more…)