You are currently browsing the archives for the code category


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 [...]

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 [...]

Update to Picased the WordPress Picasa Widget

Picasaed has been updated to version 0.4 Picasaed works pretty much the same as the Flickr Widget, but doesn't use tables, because no one likes tables. 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 [...]

XAlign, A TinyMCE Fix for WordPress

Here’s the list It is not valid strict xhtml It is deprecated transitional xhtml It does not function as expected across browsers in all cases Anyone writing new code should aim to have valid strict xhtml. Read more [...]