lunes, 11 de junio de 2007

Listar directorio con PHP

Codigo de ribafs.net
<?php
$dn = opendir (dirname(__FILE__));
$exclude = array("index.php", ".", "..");

// adiciona os arquivos ao array $arquivos
while($fn = readdir($dn)) {
if ($fn == $exclude[0] || $fn == $exclude[1] || $fn == $exclude[2]) continue;
$arquivos[] = $fn;
}
// ordena o vetor
sort($arquivos);
// exibe os arquivos
foreach ($arquivos as $arquivo)
if (is_dir($arquivo)){
$dir .= "$arquivo";
}else{
$tamanho = filesize($arquivo);
$m = 'bytes';
if ($tamanho>1024) {
$tamanho=round($tamanho/1024,2);
$m = 'KB';
} elseif($tamanho > 1024*1024){
$tamanho = round(($tamanho/1024)/1024,2);
$m = 'MB';
}
$arq .= "$arquivo - $tamanho $m";
}
echo $dir . $arq;
closedir($dn);
?>

Validacion de Email y dominios

Valida las entradas de email y dominos
codigo de Shantanu's Blog
<?php

function validate_email($email){

$exp = "^[a-z\'0-9]+([._-][a-z\'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";

if(eregi($exp,$email)){
if(checkdnsrr(array_pop(explode("@",$email)),"MX")){
print("$email is ok.
");
}else{
print("$email is ok. But domain is not.
");
}
}else{
print("$email is not ok.
");
}
}

validate_email("shantanu.ok");
validate_email("shantanu.ok@gmail.com");
validate_email("shantanu.ok@fsjaldkfjlsfjsljflsfjsldk.com");

?>

viernes, 8 de junio de 2007

Alexis prueba

typedef struct {
unsigned char d;
unsigned char m;
} Date;

void easter_c(unsigned short Y, Date *d) {
int G = (Y % 19) + 1;
int C = (int)(Y / 100) + 1;
int X = 3 * C / 4 - 12;
int Z = (8 * C + 5) / 25 - 5;
int D = 5 * Y / 4 - X - 10;
int E = (11 * G + 20 + Z - X) % 30;
if (((E == 25) &&amp; (G > 11)) || (E == 24))
++E;
int N = 44 - E;
if (N < n =" N"> 31) {
d->d = N - 31;
d->m = 4;
} else {
d->d = N;
d->m = 3;
}