Information Archives

Create your own search engine using Alexa Web Search Platform

Last night Alexa announced that they are opening up their entire database, including server services to developers in exchange for consumption fees. This means there is finally a database API that developers can tie into for commercial purposes with the fees clearly outlined. One of the things that appeals to me, which I’m sure other […]

Detecting and filtering patterns

I’ve been noticing a pattern in the comment spam being received on a couple of our blogs. See the following comment:

A couple things I noticed about the pattern:
- comment spam frequently comes from blogspot.com
- starts with hyperlink and then contains a sentence or two of text, usually nonsense
Let’s write some code to filter any HTML […]

The importance of ongoing learning

Normally I save the philosophical stuff for other blogs (and promise not to do too much of this here), but this morning an important topic came up in the #scriptschool chat (irc.scriptschool.com #scriptschool) related to PHP: ongoing learning.
I’m a huge proponent of ongoing learning. It’s important not just to learn something but to use […]

Search and research file extensions with FILExt

We have a Sony VAIO laptop that came preinstalled with Callisto’s Photoparade Slideshow and all my PHP scripts that I downloaded tried to open in that program because it had the .php extension. I changed the association to open in notetab light.
The time will come in your programming and computing travels that you come […]

Brief explanation of how to use arguments and globals inside functions

The concept of globalization, functions and arguments can be confusing to those who are new to programming. It’s not too complicated if you look at a very basic example. The following function isn’t very practical, but it works.

<?php
function addThis($a,$b) {
return $a + $b;
}
$sum_of_these = addThis(8,3); // assigns the value of 11 to the variable $sum_of_these
?>

In […]

11 built-in PHP sorting options summarized and reference

PHP has 11 different built-in sorting options as of this writing and the manual, though offering good examples of how to use most of them, doesn’t really put them all on one single, quick summarized reference page. Here’s my attempt at doing just that.
sort - sort alphabetically (a-z) or numerically (0-9)
rsort - sort reverse-alphabetically (z-a) […]

get_defined_vars returns defined variables

Today in the #scriptschool chat we talked about how to get the current defined variables used in a script. Check out the following code which illustrates the use of get_defined_vars(). The variables set will be at the end of the output:

<?php
$myname = ‘TDavid’;
$mydomains = array(‘http://www.php-scripts.com’,‘http://www.tdscripts.com/’);
$arr = get_defined_vars();
echo ‘<pre>’;
var_dump($arr);
echo ”;
?>

This is particularly useful for keypoint checking/debugging.

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

Anti-PHP articles

While it’s our intention to use this blog primarily for informational and educational posts and very little controversy, the whole “PHP sucks” crowd does deserve at least a small voice in any serious evaluation of PHP. One of the common slams against PHP is in developing larger websites.
Edward Martin wrote an article entitled Why Php […]

Changing databases inside code

To change MySQL databases within code use the mysql_select_db() function like this:

<?php
 mysql_select_db(‘db_2′, $mysql_link);
$query = “SELECT username from user where userid = ‘$user_id’”;
$result = mysql_query($query,$mysql_link);
        if(mysql_num_rows($result)) {
                $row = mysql_fetch_row($result);
                $username = $row[0];
        }
mysql_select_db(‘db_1′, $mysql_link);
?>

This code […]