Displaying posts filed under

PHP

Feb
16
2010

Fix PHP unknown Error 324

When I debugged an PHP application, an mystery error message show up. Google Chrome shows the following message:
This webpage is not available.
The webpage at XXXXXX might be temporarily down or it may have moved permanently to a new web address.
More information on this error
After click the plus sign at the last sentence, I got the [...]

Jan
11
2010

Fetch files from remote server automatically in PHP

PHP provides multiple ways to download and upload files to remote servers, such as fopen, fsockopen, cURL library, and other methods. fopen is the simplest but not the best. A while ago I wrote a function to fetch remote file by using fsockopen. However, I found a lot of problems when I use it. Then [...]

Jan
1
2010

A PHP class for manipulation of dates

The following PHP code includes a simple class that can manipulate dates, such as date subtraction, adding days and subtracting days to the current date. It is very useful because my PHP server does not support the latest DateTime function yet.

<?php

class Dt
{
private $day;
private $month;
private $year;
private $seconds=86400;

function __construct()
{
$this->day=date(“j”);
$this->month=date(“n”);
$this->year=date(“Y”);
}

function now_diff($by,$bm,$bd)
{
$bm=preg_replace(“/[0](.+)/is”,”\\1″,$bm);
$bd=preg_replace(“/[0](.+)/is”,”\\1″,$bd);
$bt=mktime(0,0,0,$bm,$bd,$by);
$nt=mktime(0,0,0,$this->month,$this->day,$this->year);
$df=$nt-$bt;
$dn=$df/$this->seconds;
return [...]

Jan
1
2010

A PHP class for generating tag clouds

The following PHP code is a simple class that can generate tag cloud in any web pages.

<?php

class TagCloud
{
private $_counts = array();
private $_tags = array();
private $_urls = array();
private $_levels = array();
private $__level = 10;

function __construct()
{
}

function add($tag,$count,$url)
{
$this->_counts[$tag] = “$count”;
$this->_tags[$tag] = “$tag”;
$this->_urls[$tag] = “$url”;
}

function css()
{
$css = “#htmltagcloud { text-align: center; line-height: 1; }\n”;
for ($l=0; $l<$this->__level; $l++)
{
$font [...]

Dec
30
2009

Database migration: MS Access to MySQL server

The Problem
Recently I solved a database migration problem: migrate MS Access database encoded in GB2312 to MySQL server encoded in UTF-8. I’d like to share what I did and hope it is useful to help you solve your problem.
I had a lot of useful data in an MS Access database. They were collected through [...]

Nov
26
2009

Display stock charts on your own website

Plain stock chart
In searching an easy way to display stock charts on a web page hosted in a web server, two useful scripts were found on the internet:
1. Easy Yahoo stock chart ASP.NET Page
2. Displaying a daily chart for a ticker symbol
Even the scripts were written in different languages, they use a common idea that [...]

Sep
3
2009

Save uploaded file to an given folder

If you use PHP upload file to web server, you have to move the uploaded file from the temp directory to a given folder. Here is generic PHP function to fulfill this job. The function does not need any input parameters but return the save filename. The filename is automatically generated based system date and [...]

Sep
2
2009

A gneric PHP function for fetching remote files

This is a generic PHP function for fetch data remotely. It takes one the remote URL as the only input variable. It returns the saved file name. All data files fetched from remote servers will save to “www-content” folder under web root directory. You can change this name to a folder name you want. The [...]