Categories

Check a url exists

function url_exists($url)
{
$ch = curl_init($url);

curl_setopt($ch,CURLOPT_HEADER,true);
curl_setopt($ch,CURLOPT_POST,false);
curl_setopt($ch,CURLOPT_FAILONERROR,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_exec($ch);
$curlInfo = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close ($ch);

if ($curlInfo != 200 && $curlInfo != 302 && $curlInfo != 304)
{
return false;
}
else
{
return true ;
}
}

php and java example

<?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

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

Shorten a URL

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

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

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