18 wrz 2009

Obliczanie różnicy czasu

echo (strtotime("2009-09-14 15:55:00")-strtotime("2009-09-14 11:00:02"));
$hour_ts = 3600;
$day_ts = 86400;
$modif_ts = strtotime("-10 day");
$modif_ts = strtotime("-4 hours");
$modif = strtotime("2009-09-14 15:55:00");
$modif_ts = strtotime($modif);
$now_ts = time()+1;
$d_ts = $now_ts-$modif_ts;
echo $d_ts .'';
4 sie 2009

Sprawdzanie osiągalności adresów url

function curlRequest($url) {
  $ch=curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  curl_setopt($ch, CURLOPT_HEADER, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_NOBODY, true);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

  $httpHeader = array(
    "Content-Type: text/xml; charset=UTF-8",
    "Content-Encoding: UTF-8"
  );

  curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);

  $data=curl_exec($ch);
  $info=curl_getinfo($ch);
  $errno=curl_getinfo( $ch, CURLINFO_HTTP_CODE );
  $finalurl=curl_getinfo( $ch, CURLINFO_EFFECTIVE_URL );

  curl_close($ch);

  if(preg_replace("/\/$/", "", $finalurl)==preg_replace("/\/$/", "", $url))
    $finalurl = ";
    return $errno.'|'.$finalurl;
}

$urls = 'www.wolakorybutowa.pl';
$tab_urls = preg_split('//', $urls, -1, PREG_SPLIT_OFFSET_CAPTURE);

for($i=0; $i $data = curlRequest('http://'.trim(chop($tab_urls[$i][0])));
  $tab_urls[$i][1] = $data;
}
print_r($tab_urls);
4 sie 2009

Wykonanie kilku przekierowań 301, 302

RewriteRule ^panel/test1.php /panel/test2.php [R=301]
RewriteRule ^panel/test2.php /panel/test3.php [R=302]
RewriteRule ^panel/test3.php /panel/test4.php [R=301]
RewriteRule ^panel/test4.php /panel/test5.php [R=302]
RewriteRule ^panel/test5.php /panel/test6.php [R=301]

przydatne do testów
plik test6.php:

<? sleep(20); ?>

OK

23 lip 2009

Sprawdzenie poprawności obrazka

if($_FILES['foto']['tmp_name']) {

$tab = getimagesize($_FILES['foto']['tmp_name']);
 $width = $tab[0];
 $height = $tab[1];
 $mime = $tab['mime'];

if($width<600 && $height<400) 
  $errors[]='złe wymiary zdjęcia, minimalne wymiary 600x400';

if(!preg_match("/(jpg|jpeg|png|gif)/", $mime)) 
  $errors[]='zły format zdjęcia';
}
23 lip 2009

Dodanie do daty akutalnej godziny

echo date('H:i:s', strtotime('now')) . ' ';
echo date('Y-m-d', strtotime("+2 days")) . ' ' . date('H:i:s', strtotime('now')) . '';
$task_dateend = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime("+2 days")) . ' ' . date('H:i:s', strtotime('now'))));
echo $task_dateend;

Wynki:
2009-07-25 14:02:51