Dead Simple PHP Calendar
I needed a calendar for a PHP project I was working on. I did a quick look around and found some promising solutions, but they all seemed way more complex than what I wanted. They also used tables, which are gross. This is a ridiculously easy way to get a calendar from php:function calendar($date=false){
$date_parts=(!$date)?preg_split("/[-]+/",$date):preg_split("/[-]+/",date('Y-m-d'));
$year=$date_parts[0];$month=$date_parts[1];$day=$date_parts[2];
$time=mktime(0,0,0,$month,1,$year);
$month_name=date('F',$time);
$days_in_month=cal_days_in_month(CAL_GREGORIAN,$month,$year);
$first_day=date('w',$time);
$calendar=''.$month_name.' Read more [...]
Count Characters, but Not HTML or Links
I took a lazy Google look and didn't see how to do this. If you want to use PHP to count characters in a string but only the visible text (in other words you don't want to count the html— like links and whatnot), then just use this function. It returns the string length.
function visible_count($str){
echo strlen(strip_tags($str));
}
Of if you want to reject a string that is too long, try the below. It returns true if the string is within a limit, false if it exceeds the limit. Modify at as Read more [...]
The Perils of Using a Free WordPress Theme
Take a look at what happened to this blog's hit counts after switching (briefly) to a new and free WordPress theme downloaded from the official WordPress website.
Before I used my own variation of the freely available sandbox theme. I switched after updating the template andlosing some of my work on it. Now I've gone back with though I haven't put any real effort into making the site look "good."
Since replacing the theme, my site's stats have returned to normal. I won't name the theme that killed Read more [...]
Hiding PHPSESSID
All you need to do is add php_flag session.use_trans_sid off to the .htaccess file and bang! to your php files, but why add that to all your files when you can add one line to your .htaccess file? Read more [...]
Generating a Random User Password in PHP
Creating a custom random password generator in PHP isn't difficult, for my purposes I often use this simple function // $group is the characters we want the password possibly composed of // $pass_length is the length we want our password to be function random_password($group, $pass_length){ for($p=0; Read more [...]
A PHP Fischer Random Chess Function
// remove the square the bishop got from the array of possible squares // get the second bishop $tmp = array_rand(array(1=>'b',3=>'d',5=>'f',7=>'h')); } // return an array of the pieces, the array keys correspond to the squares and their values to pieces occupying those squares return array( $rook1.'1'=>'rl', $rook2.'1'=>'rl', $knight1.'1'=>'nl', $knight2.'1'=>'nl', $bishop1.'1'=>'bl', $bishop2.'1'=>'bl', $queen.'1'=>'ql', $king.'1'=>'kl', $rook1.'8'=>'rd', $rook2.'8'=>'rd', $knight1.'8'=>'nd', $knight2.'8'=>'nd', $bishop1.'8'=>'bd', $bishop2.'8'=>'bd', $queen.'8'=>'qd', $king.'8'=>'kd', 'a7'=>'pd', 'b7'=>'pd', 'c7'=>'pd', 'd7'=>'pd', 'e7'=>'pd', 'f7'=>'pd', 'g7'=>'pd', 'h7'=>'pd', 'a2'=>'pl', 'b2'=>'pl', 'c2'=>'pl', 'd2'=>'pl', 'e2'=>'pl', 'f2'=>'pl', 'g2'=>'pl', 'h2'=>'pl'); Read more [...]
Here's Some Chess
Sometime around May 2006 I got this idea to make a Chess server that uses only PHP. There are lots of boring reasons for the PHP part, but the reason for making the server was that I had friends who I played chess with and a bunch of people (including myself) we're moving all over the place so it would be difficult to keep playing. chess, chess program, chess server, mysql, open source, php, php chess, some chess, web chess Read more [...]
