<?php
function check_alive($url, $timeout = 10, $successOn = array(200, 301)) {
$ch = curl_init($url);
// Set request options
curl_setopt_array($ch, array(
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_NOBODY => true,
CURLOPT_TIMEOUT => $timeout,
CURLOPT_USERAGENT => "page-check/1.0"
));
// Execute request
curl_exec($ch);
// Check if an error occurred
if(curl_errno($ch)) {
curl_close($ch);
return false;
}
// Get HTTP response code
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Page is alive if 200 OK is received
//return $code;
return in_array( $code, $successOn );
}
$checks = array(
'http://www.google.co.uk',
'http://www.facebook.com',
'http://www.bbc.co.uk',
'http://photogabble.co.uk',
'http://youtube.com'
);
foreach($checks as $check)
{
echo $check . ' is ' . ( (check_alive($check) ) ? 'Alive' : 'Dead' ) . "\n";
}
<a href="" id="csv-export">export</a>
<iframe id="downloadIframe" src="" style="height: 0px; width: 0px; display: none;"></iframe>
<script>
$("#csv-export").click(function(e){
e.preventDefault();
oIFrm = document.getElementById('downloadIframe');
oIFrm.src = '' // URL to download file -- via php download headers;
});
</script>
<?php
$out = iconv('utf-8', 'windows-1250//TRANSLIT', $out);
$filename = 'katalog-export___' . date('YmdHis') . '.csv';
header('Content-Encoding: windows-1250');
header('Content-type: text/csv; charset=windows-1250');
header('Content-Disposition: attachment; filename=' . $filename);
//echo "\xEF\xBB\xBF"; // UTF-8 BOM
echo $out;
exit(0);
?>
function validateDate($date, $format = 'Y-m-d H:i:s')
{
$d = DateTime::createFromFormat($format, $date);
return $d && $d->format($format) == $date;
}
var_dump(validateDate('2012-02-28 12:12:12')); # true
var_dump(validateDate('2012-02-30 12:12:12')); # false
var_dump(validateDate('2012-02-28', 'Y-m-d')); # true
var_dump(validateDate('28/02/2012', 'd/m/Y')); # true
var_dump(validateDate('30/02/2012', 'd/m/Y')); # false
var_dump(validateDate('14:50', 'H:i')); # true
var_dump(validateDate('14:77', 'H:i')); # false
var_dump(validateDate(14, 'H')); # true
var_dump(validateDate('14', 'H')); # true
var_dump(validateDate('2012-02-28T12:12:12+02:00', 'Y-m-d\TH:i:sP')); # true
# or
var_dump(validateDate('2012-02-28T12:12:12+02:00', DateTime::ATOM)); # true
var_dump(validateDate('Tue, 28 Feb 2012 12:12:12 +0200', 'D, d M Y H:i:s O')); # true
# or
var_dump(validateDate('Tue, 28 Feb 2012 12:12:12 +0200', DateTime::RSS)); # true
var_dump(validateDate('Tue, 27 Feb 2012 12:12:12 +0200', DateTime::RSS)); # false
# ...
<?php
function dateRange( $first, $last, $step = '+1 day', $format = 'Y/m/d' ) {
$dates = array();
$current = strtotime( $first );
$last = strtotime( $last );
while( $current <= $last ) {
$dates[] = date( $format, $current );
$current = strtotime( $step, $current );
}
return $dates;
}
?>
<?
$out = '';
$fields = dibi::fetchAll("SHOW COLUMNS FROM web_application");
foreach ($fields as $field)
{
$out .= '"'.$field->Field.'";';
}
$out = rtrim($out, ';');
$out .= PHP_EOL;
foreach ($this->model->csvExport() as $index => $row)
{
foreach ($row as $r)
{
$out .='"'.$r.'";';
}
$out = rtrim($out, ';');
$out .= PHP_EOL;
}
$out = iconv('utf-8', 'windows-1250', $out);
$filename = 'application-export___' . date('YmdHis') . '.csv';
header('Content-Encoding: windows-1250');
header('Content-type: text/csv; charset=windows-1250');
header('Content-Disposition: attachment; filename=' . $filename);
//echo "\xEF\xBB\xBF"; // UTF-8 BOM
echo $out;
exit(0);
$this->view->setTemplateFile('modules/application/csv.php');
<?
function HumanReadableFilesize($size) {
// Adapted from: http://www.php.net/manual/en/function.filesize.php
$mod = 1024;
$units = explode(' ','B KB MB GB TB PB');
for ($i = 0; $size > $mod; $i++) {
$size /= $mod;
}
return round($size, 2) . ' ' . $units[$i];
}
function fsize($file) {
$a = array("B", "KB", "MB", "GB", "TB", "PB");
$pos = 0;
$size = filesize($file);
while ($size >= 1024) {$size /= 1024;$pos++;}
return round($size,2)." ".$a[$pos];
}
?>