Search
Syndication
Sponsors

Archive for the ‘Functions’ Category

php and java example

Friday, May 22nd, 2009

<?php
// get instance of Java class java.lang.System in PHP
$system = new Java(’java.lang.System’);
print ‘Java version=’.$system->getProperty(’java.version’).’ <br>’;
print ‘Java vendor=’ .$system->getProperty(’java.vendor’).’ <br>’;
print ‘OS=’.$system->getProperty(’os.name’).’ ‘.
$system->getProperty(’os.version’).’ on ‘.
$system->getProperty(’os.arch’).’ <br>’;
?>

using the md5 function to encrypt data

Tuesday, May 19th, 2009

<?php $secret = “password”;
$password = md5($secret);
echo $secret; echo “<br>”;
echo $password; ?>

Shorten a URL

Thursday, May 7th, 2009

This example shows how to use tinyurl’s api to genearte a short url from a url you pass, there are other services which offer this functionality

<?php
/**
 * Use tinyurl to generate a short url
 *
 * @param string $url The url that you want to shorten
 */
function ShortUrl($url)

$tinyurl = file_get_contents(”http://tinyurl.com/api-create.php?url=”.$url);
return $tinyurl;
}
//usage example
echo ShortUrl(”http://www.getphp.net/a-google-pagerank-script/“);
?>

temperature conversion function

Wednesday, May 6th, 2009

A simple temperature conversion function

<?php
function TempConv($temp,$corf)
{
    switch($corf)
 {
        case “F”:
            return (5/9)*($temp-32);
   break;
        case “C”:
            return (9/5)*$temp+32;
   break;
  default :
   echo “Error invalid conversion”;
   break;
    }
}

echo TempConv(50,”F”).’&deg;’;
echo TempConv(50,”C”).’&deg;’;
echo TempConv(50,”T”);
?>

Sign of the zodiac

Wednesday, May 6th, 2009

User submitted

<?php
function zodiac($birthdate)
{
    list($month,$day) = explode(”-”,$birthdate);
    if(($month == 3 || $month == 4) && ($day > 22 || $day < 21)){
        $zodiac = “You are an Aries”;
    }
    elseif(($month == 4 || $month == 5) && ($day > 22 || $day < 22)){
        $zodiac = “You are a Taurus”;
    }
    elseif(($month == 5 || $month == 6) && ($day > 23 || $day < 22)){
        $zodiac = “You are a Gemini”;
    }
    elseif(($month == 6 || $month == 7) && ($day > 23 || $day < 23)){
        $zodiac = “You are a Cancer”;
    }
    elseif(($month == 7 || $month == 8) && ($day > 24 || $day < 22)){
        $zodiac = “You are a Leo”;
    }
    elseif(($month == 8 || $month == 9) && ($day > 23 || $day < 24)){
        $zodiac = “You are a Virgo”;
    }
    elseif(($month == 9 || $month == 10) && ($day > 25 || $day < 24)){
        $zodiac = “You are a Libra”;
    }
    elseif(($month == 10 || $month == 11) && ($day > 25 || $day < 23)){
        $zodiac = “You are a Scorpio”;
    }
    elseif(($month == 11 || $month == 12) && ($day > 24 || $day < 23)){
        $zodiac = “You are a Sagittarius”;
    }
    elseif(($month == 12 || $month == 1) && ($day > 24 || $day < 21)){
        $zodiac = “You are a Capricorn”;
    }
    elseif(($month == 1 || $month == 2) && ($day > 22 || $day < 20)){
        $zodiac = “You are an Aquarius”;
    }
    elseif(($month == 2 || $month == 3) && ($day > 21 || $day < 21)){
        $zodiac = “You are a Pisces”;
    }
    
    return $zodiac;
}
echo zodiac(’05-24-1924′);
?>