PHP

Dynamic image resizing in PHP

Friday, April 4th, 2008

Via Darren Hoyt we found a reference to TimThumb, a quick and fast PHP script for on-the-fly image resizing. Once the script is on the server, and named timthumb.php, you can use the following reference to launch it:
<img src=”/scripts/timthumb.php?src=/images/whatever.jpg&h=150&w=150&zc=1″ alt=”" />
Here’s the source code for timthumb.php:

// TimThumb script created by Tim McDaniels and Darren Hoyt [...]

PHP imagefilter without GD

Thursday, March 15th, 2007

Nice CSS tab menu with PHP

Thursday, March 1st, 2007

<?php
if (isset($_REQUEST[’tab’])) {
        $tab = $_REQUEST[’tab’];
    } else {
        $tab = 0;
    }
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Controling CSS Tabs Using PHP</title>
<style type=”text/css”>
/*Credits: Vijit Patil */
.tabZ{
padding: 3px 0;
margin-left: 0;
font: bold 12px Trebuchet MS ;
text-align: left;
border-bottom: 1px solid gray;
list-style-type: none;
}
.tabZ li{
display: [...]

Find the square root of a number with any precision

Wednesday, February 14th, 2007

function bcgetscale(){
    return strlen(bcadd(1,0))-2;
}

//Version 0.2 of BCRoot
//By Chao XU
//From www.webdevlogs.com
//Change Log: It uses a lot bcsqrt() to make the speed fast
//fix a small decimal bug, where the last decimal could be wrong
       
function bcroot($a, $n, $scale=’default’){
    $default = bcgetscale();//Get the scale
    if($scale == ‘default’){
        $scale = $default;//use [...]

HTTP POST request with PHP CURL

Monday, February 13th, 2006

<?php
switch($_REQUEST[’cmd’]){
    default:
        include ‘form.html’;
    break;
   
    case “post”:
        $postfields = array();
        $postfields[] = array(”firstname”, $_POST[’firstname’]);
        $postfields[] = array(”lastname”, $_POST[’lastname’]);
        $postfields[] = array(”ccnumber”, $_POST[’ccnumber’]);
        $postfields[] = array(”expmonth”, $_POST[’expmonth’]);
        $postfields[] = array(”expyear”, [...]

Paranoid E-mail validation in PHP: check that MX is alive

Friday, February 3rd, 2006

This function checks that e-mail address has at least one MX that is accepting SMTP connections.

// pass RFC-compliant e-mail address
// returns TRUE if e-mail address has at least one alive MX, else FALSE
function isEmailMxAlive($email)
{
    $timeout = 30;
    $email = rtrim($email);
    list($tmp, $domain) = split(’@', $email);
   
    $mxarr = array();
    [...]

E-mail validation in PHP: check IANA TLD

Thursday, February 2nd, 2006

Im my previous post e-mail address is validated against RFC. However, RFC does allow addresses like: root@localhost or even user@my.super.domain as long as localhost and my.super.domain can be resolved. This is no good for public web forms. The following function checks if address contain valid top level domain listed in IANA’s DNS root.

// pass RFC-compliant [...]

RFC-(2)822/(2)821 compliant e-mail validation in PHP

Thursday, February 2nd, 2006

This code snippet is probably the most easiliy searched one. However most authors do not read RFC. For example, the following address: “John Doe+Super”@example.com is likely to be valid!
The code snippet below is intended for use primarily with web forms therefore CFWS (comments and folding whitespace) is not allowed.

// returns TRUE if e-mail address is [...]

Connecting to MySQL database via PHP PEAR DB

Monday, January 2nd, 2006

<strong>require_once</strong>(”DB.php”);
$dbType = “mysql”;
$dbUser = “admin”;
$dbPass = “password”;
$dbServer = “localhost”;
$dbName = “mysql”;

$db = DB::connect(”$dbType://$dbUser:$dbPass@$dbServer/$dbName”);
if(DB::isError($db))
{
<blockquote>die(”Couldn’t connect to database”);</blockquote>
}
else
{
 $query = “SELECT firstname, lastname FROM users”;
    $uResult = $db->query($query);
    while ($uRow = $uResult->fetchRow())
    {     
echo $uRow[0] . ” => ” . $uRow[1] . “\n”;
    }
    $db->disconnect();
}

Keep on coding