PHP 4.x Archives

Open source phpMyEdit

phpMyEdit:
generates PHP code for displaying/editing MySQL tables in HTML. All you need to do is to write a simple calling program (a utility to do this is included). It includes a huge set of table manipulation functions (record addition, change, view, copy, and removal), table sorting, filtering, table lookups, and more.
Download (gz).

Apache + PHP on Mac OS X

Though the screenshots have changed the basic process is the same, Kevin Hemenway, takes readers through how to setup an Apache server on Mac OS X and then how to turn on PHP 4.
To edit the httpd.conf I needed to do the following:
1. start Terminal by going to Utilities/Terminal
2. type the following into the terminal:
sudo […]

AJAX MyTop

Man, how many clicks does it take to get the download these days at Sourceforge? Seems like it took me a half dozen to get to the AjaxMyTop project download.

MyTop creator Jeremy Zawodny writes:
Someone has built and AJAX powered version of mytop, the little console based MySQL monitoring tool I wrote years ago. I guess […]

Query results within last X days

Sometimes it is necessary to query data from the last 7 days. Here’s how to create a dynamic query inside a script using PHP / MySQL to return a list of users who last visited within X number of days (7 by default):

<?php
$now = time(); // this is the current UNIX timestamp for the server
$days […]

Turck MMCache and PHP encoder

I’m not sure how current or updated this is because I found some broken project links (all links below work) but these projects seem promising and worth closer inspection, especially if one is looking to make their PHP scripts run faster.
Turck MMcache:
… a free open source PHP accelerator, optimizer, encoder and dynamic content cache for […]

Parsing names and numbers out of text

At one of our sites we needed to parse out some names and numbers from a log file. The strings also contained comment text and the order would be mixed format. These types of regular expression parsing can be tricky.
Let’s take a look at the two possible formats of the strings:
FORMAT #1:
[00:02:18][jvastine]7.52..I agree with […]

Using header to redirect the browser

The PHP header function allows redirection of the browser, among other cool things.
Example redirecting the browser to php-scripts.com homepage:

<?php
header(”Location: http://www.php-scripts.com/”);
?>

Using floor and time to calculate number of days elapsed from UNIX timestamp

Finding out the number of days elapsed from a UNIX timestamp is actually pretty straightforward. If you only know two dates then first you’ll need to convert the date to a UNIX timestamps and then subtract the most recent timestamp from the older timestamp like this:

<?php
$old_timestamp = 1102971600;
$elapsed_seconds = time() - $old_timestamp;
print ‘Seconds elapsed since […]

How to use preg_replace to replace phrase between question marks

<?php
$string = “?This is a test that should be in single quotes quotes?”;
$text = preg_replace(”/(\?([^\?]+)\?)/”,”‘\\2′”,$string);
?>

regular expression produces:
This is a test that should be in single quotes’

How to make an anniversary counter announcement script using ordinal numbers

Today being it is our 16th wedding anniversary I decided it would be appropriate to build a small script to keep track and post a message automatically on our special day together. I wanted this program to remember what year of our anniversary it was without me having to remind it: a great use for […]