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
// 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>’;
?>
<?php $secret = “password”;
$password = md5($secret);
echo $secret; echo “<br>”;
echo $password; ?>
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/“);
?>
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”).’°’;
echo TempConv(50,”C”).’°’;
echo TempConv(50,”T”);
?>
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 [...]