<?php
$free_space = diskfreespace("C:\");
//echo $free_space; //bytes
//echo $free_space/1024/1024; //megabytes
echo $free_space/1024/1024/1024 . " gigabytes";
?>
kaynak: ordan burdan
<?php
$items = array("php", "asp", "javascript");
if (in_array("php", $items))
{
echo "found php in the array";
}
else
{
echo "cannot find the search term";
}
?>
kaynak: ordan burdan
<?php
$url="http://www.otelreferans.com";
$var = fread_url($url);
preg_match_all ("/img[s]+[^>]*?src[s]?=[s"']+".
"(.*?)["']+.*?>"."([^<]+|.*?)?</img>/",$var, &$matches);
$matches = $matches[1];
$list = array();
foreach($matches as $var)
{
print($var."<br>");
}
// The fread_url function allows you to get a complete
// page. If CURL is not installed replace the contents with
// a fopen / fget loop
function fread_url($url,$ref="")
{
if(function_exists("curl_init")){
$ch = curl_init();
$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; ".
"Windows NT 5.0)";
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt( $ch, CURLOPT_HTTPGET, 1 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION , 1 );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION , 1 );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_REFERER, $ref );
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
$html = curl_exec($ch);
curl_close($ch);
}
else{
$hfile = fopen($url,"r");
if($hfile){
while(!feof($hfile)){
$html.=fgets($hfile,1024);
}
}
}
return $html;
}
?>
örnek;
kaynak: ordan burdan
<?php
$url=”http://www.otelreferans.com”;
$var = fread_url($url);
preg_match_all (”/a[s]+[^>]*?href[s]?=[s"']+”.
“(.*?)["']+.*?>”.”([^<]+|.*?)?</a>/”,
$var, &$matches);
$matches = $matches[1];
$list = array();
foreach($matches as $var)
{
print($var.”<br>”);
}
// The fread_url function allows you to get a complete
// page. If CURL is not installed replace the contents with
// a fopen / fget loop
function fread_url($url,$ref=”")
{
if(function_exists(”curl_init”)){
$ch = curl_init();
$user_agent = “Mozilla/4.0 (compatible; MSIE 5.01; “.
“Windows NT 5.0)”;
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt( $ch, CURLOPT_HTTPGET, 1 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION , 1 );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION , 1 );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_REFERER, $ref );
curl_setopt ($ch, CURLOPT_COOKIEJAR, ‘cookie.txt’);
$html = curl_exec($ch);
curl_close($ch);
}
else{
$hfile = fopen($url,”r”);
if($hfile){
while(!feof($hfile)){
$html.=fgets($hfile,1024);
}
}
}
return $html;
}
?>
kaynak: ordan burdan
<?php
$numrows = 30;
$changestyle = 2;
print("<table>");
for($i=0;$i<$numrows;$i++)
{
print("<tr ".(!($i%$changestyle)?"style="background-color:#afafaf;"":"").
"><td> $i </td></tr>");
}
print("</table>");
?>
kaynak: ordan burdan
<?php
$count = 0;
if(!empty($searchurl))
{
$searchurl = str_replace("%2E",".",$searchurl);
$filename = "http://www.google.com/search?sourceid=navclient&".
"ie=UTF-8&q=site%3A$searchurl";
$file = fopen($filename, "r");
if (!$file)
{
echo "<p>Unable to open remote file $filename.
";
}
else
{
while (!feof($file))
{
$var = fgets($file, 1024);
if(eregi("of about <b>(.*)</b> from",$var,$out))
{
$out[1] = strtolower(strip_tags($out[1]));
$count = $out[1];
break;
}
}
fclose($file);
}
if($count)
{
$result = "The site $searchurl has $count pages listed";
}
else
{
$result = "The site $searchurl is not spidered";
}
}
?>
kaynak: ordan burdan
<?php
// This array of values is just here for the example.
$values = array("23","32","35","57","12",
"3","36","54","32","15",
"43","24","30");
// Get the total number of columns we are going to plot
$columns = count($values);
// Get the height and width of the final image
$width = 300;
$height = 200;
// Set the amount of space between each column
$padding = 5;
// Get the width of 1 column
$column_width = $width / $columns ;
// Generate the image variables
$im = imagecreate($width,$height);
$gray = imagecolorallocate ($im,0xcc,0xcc,0xcc);
$gray_lite = imagecolorallocate ($im,0xee,0xee,0xee);
$gray_dark = imagecolorallocate ($im,0×7f,0×7f,0×7f);
$white = imagecolorallocate ($im,0xff,0xff,0xff);
// Fill in the background of the image
imagefilledrectangle($im,0,0,$width,$height,$white);
$maxv = 0;
// Calculate the maximum value we are going to plot
for($i=0;$i<$columns;$i++)$maxv = max($values[$i],$maxv);
// Now plot each column
for($i=0;$i<$columns;$i++)
{
$column_height = ($height / 100) * (( $values[$i] / $maxv) *100);
$x1 = $i*$column_width;
$y1 = $height-$column_height;
$x2 = (($i+1)*$column_width)-$padding;
$y2 = $height;
imagefilledrectangle($im,$x1,$y1,$x2,$y2,$gray);
// This part is just for 3D effect
imageline($im,$x1,$y1,$x1,$y2,$gray_lite);
imageline($im,$x1,$y2,$x2,$y2,$gray_lite);
imageline($im,$x2,$y1,$x2,$y2,$gray_dark);
}
// Send the PNG header information. Replace for JPEG or GIF or whatever
header ("Content-type: image/png");
imagepng($im);
?>
kaynak: ordan burdan
function odbc_fetch_array_custom($id_res)
{
// Clear our return variable
unset($ar);
// Get the number of fields in the returned result
$colnum = odbc_num_fields($id_res);
// Fill an array with the column headers
// We do this here to save API calls.
for($i=1; $i<=$colnum;$i++)$field_name[$i]=odbc_field_name($id_res,$i);
// If we have a result
if (odbc_fetch_row($id_res))
{
// Fill our return array with the column data
for ($i = 1; $i <= $colnum; $i++)
$ar[$field_name[$i]] =
odbc_result($id_res, $field_name[$i]);
return $ar;
}
else
{
return false;
}
}
?>
örnek
<?php
$db = "monkeys";
// odbc_connect_custom was in part 1
$connection_id = odbc_connect_custom($db);
$query = "SELECT name,amount FROM monkey_types";
$result_id = odbc_exec($connection_id,$query);
while($result=odbc_fetch_array_new($result_id))
{
// Do whatever we want with the row
print($row["name"]."<br>");
print($row["butt_color"]."<br>");
}
?>
kaynak: ordan burdan
<?php
function odbc_connect_custom($db)
{
$dbdir = "D:InetpubwwwrootDatabases\";
$cfg_dsn = "DRIVER=Microsoft Access Driver (*.mdb);
DBQ=".$dbdir.$db.".mdb;UserCommitSync=Yes;
Threads=3;
SafeTransactions=0;
PageTimeout=5;
MaxScanRows=8;
MaxBufferSize=2048;
DriverId=281;
DefaultDir=C:/ProgramFiles/CommonFiles/ODBC/DataSources";
// The DefaultDir setting will probably be ok if you have gone for
// a typical installation
$cfg_dsn_login = "";
$cfg_dsn_mdp = "";
return odbc_connect($cfg_dsn,$cfg_dsn_login,$cfg_dsn_mdp);
}
?>
örnek :
<?php
$db = "monkeys";
$connection_id = odbc_connect_custom($db);
$query = "SELECT * FROM monkey_types";
$result_id = odbc_exec($connection_id,$query);
?>
kaynak: ordan burdan
function alertSize() {
var myWidth = 0, myHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
window.alert( 'Width = ' + myWidth );
window.alert( 'Height = ' + myHeight );
}
kaynak: ordan burdan
<?
$test_data=array(0.5,6,12,17,2,0.3,9);
echo "<img src=http://chart.apis.google.com/chart?chtt=".urlencode("Code Kodu Deneme")."&cht=lc&chs=450×125&chd=".chart_data($test_data).">";
function chart_data($values) {
$maxValue = max($values);
$simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$chartData = "s:";
for ($i = 0; $i < count($values); $i++) {
$currentValue = $values[$i];
if ($currentValue > -1) {
$chartData.=substr($simpleEncoding,61*($currentValue/$maxValue),1);
}
else {
$chartData.='_';
}
}
return $chartData."&chxt=y&chxl=0:|0|".$maxValue;
}
?>
kaynak: ordan burdan
function write($path, $content, $mode="w+"){
if (file_exists($path) && !is_writeable($path)){ return false; }
if ($fp = fopen($path, $mode)){
fwrite($fp, $content);
fclose($fp);
}
else { return false; }
return true;
}
örnek :
write('test.txt', 'Test content');
kaynak: ordan burdan
$captchaFolder = 'temp/';
// Filetypes to check (you can also use *.*)
$fileTypes = '*.jpg';
// Here you can define after how many
// minutes the files should get deleted
$expire_time = 20;
// Find all files of the given file type
foreach (glob($captchaFolder . $fileTypes) as $Filename) {
// Read file creation time
$FileCreationTime = filectime($Filename);
// Calculate file age in seconds
$FileAge = time() - $FileCreationTime;
// Is the file older than the given time span?
if ($FileAge > ($expire_time * 60)){
// Now do something with the olders files…
print "The file $Filename is older than $expire_time minutes
";
// For example deleting files:
//unlink($Filename);
}
}
kaynak: ordan burdan
function listdir_by_date($path){
$dir = opendir($path);
$list = array();
while($file = readdir($dir)){
if ($file != '.' and $file != '..'){
// add the filename, to be sure not to
// overwrite a array key
$ctime = filectime($data_path . $file) . ',' . $file;
$list[$ctime] = $file;
}
}
closedir($dir);
krsort($list);
return $list;
}
örnek :
listdir_by_date('data/');
kaynak: ordan burdan
function IsIPValid($ip){
if (preg_match('/^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$/', $ip)){
return true;
}
return false;
}
örnek:
var_dump(IsIPValid('192.168.100.1'));
// => bool(true)
var_dump(IsIPValid('192…1'));
// => bool(false)
var_dump(IsIPValid('127001'));
// => bool(false)
var_dump(IsIPValid('127.0.0.1'));
// => bool(true)
kaynak: ordan burdan
function GetBetween($content,$start,$end){
$r = explode($start, $content);
if (isset($r[1])){
$r = explode($end, $r[1]);
return $r[0];
}
return '';
}
örnek :
GetBetween('foo test bar', 'foo', 'bar');
// –> returns ' test ';
kaynak: ordan burdan
function array_changecase($a, $c='l'){
return array_change_key_case($a,($c=='u') ?
CASE_UPPER : CASE_LOWER);
}
örnek
array_changecase(array("foO" => "bar", "noNe" => 1), 'u')
returns:<br/>array("FOO" => "bar", "NONE" => 1)
kaynak: ordan burdan
var str = 'AbCdEfGhIjKlMnOpQrStUvWxYz';var result = str.toLocaleUpperCase();document.writeln(result); // Outputs: ABCDEFGHIJKLMNOPQRSTUVWXYZ
kaynak: ordan burdan
var str = 'AbCdEfGhIjKlMnOpQrStUvWxYz';var result = str.toLocaleLowerCase();
document.writeln(result); // Outputs: abcdefghijklmnopqrstuvwxyz
kaynak: ordan burdan
var str='The quick brown fox';
var speed = str.substr(4,5); // contains: quick
var speed = str.substr(4); // contains: quick brown fox
var speed = str.substr(4,-2); // contains: ''
kaynak: ordan burdan
str = "One~Two~Three~Four~Five";
newArray = str.split('~');
for(i=0; i<newArray.length; i++) {
document.writeln(i+'-'+newArray[i]+'<BR>');
}
// outputs:
// 0-One
// 1-Two
// 2-Three
// 3-Four
// 4-Five
kaynak: ordan burdan
str = "Jenny's Number is 867-5309. At least back in the 80's. The 80's were cool.";
result = str.replace("Jenny's", "Bob's"); // Replace Jenny's With Bob's
document.writeln(result);
// outputs:
//Bob's Number is 867-5309. At least back in the 80's. The 80's were cool.
kaynak: ordan burdan