September PHP-Scripts Blog Archives

Buying PHP shares in Yahoo Buzz Game

Yahoo in association with O’Reilly is running a free game called Yahoo Buzz Game where players are given $10,000 virtual dollars to buy into various technologies and news. Of course the first thing I bought into was PHP (shown above) but there are plenty of other markets (shown below):

The game is being powered by […]

How to PHP scripting course begins Friday 9/23/2005

For those who would like to learn how to write PHP code, starting next Friday at Webmaster Cookbook, our family friendly webmaster how-to site/blog, we’ll be going through a 32 week course on PHP programming. Details will be announced during the radio show and podcast next Friday September 23, 2005 at 3:30pm PST. For those […]

Fixing the start PHP spacing bug in Code Snippet v1.4 WP plugin

Noticed yesterday that the WP PHP code snippet plugin we’re using (thanks Lestat, for pointing to it) is adding an erroneous space between the < and ?. Those who are using this plugin v1.4 and readers should beware that the code examples with the start PHP tag may have an erroneous space being added […]

How to change the server date and time

This is more a Linux task than a PHP one, but for those needing to change their server date/time, it can be done with the linux DATE command as follows:

date - s `+ 1500`

This might require root or sudo privileges. In that case the command would be:

sudo date - s `+ 1500`

On a PHP note, […]

How to join an ID list using IN MySQL function

How to create a query list of ID numbers using join from an $array and put into a string that can be used in a MySQL query:

$id_numbers = array(1,6,14,32,84,27,49,77);
$complist = join(”,”, $id_numbers);
$query = “SELECT id from tablename WHERE id IN($complist)”;

How to strip off last two characters from string using substr

substr comes in handy if you need to strip characters off the end of a string.

<?php
$test_string = ‘item 1, item 2, item 3, ‘;
$test_string = substr($test_string,0,-2);
echo($test_string); // returns “item 1, item 2, item 3″
?>

How to check the user’s browser type and platform

Sooner or later it might become necessary to write an application that tracks site visitor browser types. Here’s some code to use:

<?php
echo($_SERVER[‘HTTP_USER_AGENT’]);
?>

This will output something that looks like one of the following:

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) 
Mozilla/4.0 (compatible; MSIE 5.0; Mac_PowerPC)
Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)
Mozilla/5.0 (Windows; U; Windows NT 5.1; […]

Google Adwords API

It’s called the APIlity Library and it allows interaction with the Google Adwords program:
The APIlity PHP Library provides an object-oriented way to easily access and manage the Google AdWords API from within PHP. This comes along with an abstraction from the SOAP and WSDL details.
Requirements (also from the sourceforge page):

APIlity works both with PHP4 and […]

How to tell if the cURL extension is enabled

To determine if the cURL extension is enabled, run the following code on your server:

<?php
var_dump(curl_version());
?>

Success! - If cURL exists and is enabled it should return something that looks like this:
PHP version 4 example successful result:

string(54) "libcurl/7.13.2 OpenSSL/0.9.7e zlib/1.2.2 libidn/0.5.13"

PHP version 5.1 example successful result (returns an array)

Array
(
   [version_number] => 461570
   [age] => 1
   [features] […]

Colorized pretty source code htaccess method

Tired of black and whit coding that looks like what’s above? Want to colorize it to look like this instead:

Here is how to make colorized pretty source code using the .htacess method for .phps files:
Step 1. create a text file and save it as .htaccess. Put the following code in the file:

AddType application/x-httpd-php-source .phps

Step 2. […]