Funzione per controllare un range di date
Funzione per controllare che tra due date ci siano tot giorni
// $from => data inziale
// $to => data finale
// $max => numero massimo di giorni per il range
function check_date_range($from, $to, $max)
{
$u_to = strtotime($to);
$u_from = strtotime($from);
$u_diff = $u_to - $u_from;
$days_diff = $u_diff / 60 / 60 / 24;
// se tra il from e il to ci sono più di $max giorni
if( $days_diff > $max )
return false;
else
return true;
}
// $to => data finale
// $max => numero massimo di giorni per il range
function check_date_range($from, $to, $max)
{
$u_to = strtotime($to);
$u_from = strtotime($from);
$u_diff = $u_to - $u_from;
$days_diff = $u_diff / 60 / 60 / 24;
// se tra il from e il to ci sono più di $max giorni
if( $days_diff > $max )
return false;
else
return true;
}
Regexp per validare una URL
Pattern ragionevolmente semplice per validare con una regular expression una URL.
Credits: http://www.weberdev.com/get_example-4227.html
if(!preg_match("/^[a-zA-Z]+(:\/\/)+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&#=\?\-_]+$/i", $url))
print "Bad URL";
print "Bad URL";
Conoscere via php qual'è l'ultimo giorno di un certo mese
Dato un mese e l'anno torna l'ultimo giorno di quel mese.
function get_last_day_of_month($month, $year)
{
$month = (int)$month;
$year = (int)$year;
$day = 31;
while( !checkdate($month, $day, $year) )
--$day;
return $day;
}
{
$month = (int)$month;
$year = (int)$year;
$day = 31;
while( !checkdate($month, $day, $year) )
--$day;
return $day;
}
Script per aggiornare chrome/chromium all'ultima versione
Lo script si collega al repository delle snapshot dello sviluppo di chromium per linux e scarica l'ultima build.
Scarica il file e lo scompatta nella home dell'utente che sta eseguendo lo script.
Basta eseguire lo script per aggiornare chromium all'ultima versione.
#!/bin/bash
wget http://build.chromium.org/buildbot/snapshots/chromium-rel-linux/`wget -q -O - http://build.chromium.org/buildbot/snapshots/chromium-rel-linux/LATEST`/chrome-linux.zip
unzip -o chrome-linux.zip -d $HOME/
rm chrome-linux.zip
wget http://build.chromium.org/buildbot/snapshots/chromium-rel-linux/`wget -q -O - http://build.chromium.org/buildbot/snapshots/chromium-rel-linux/LATEST`/chrome-linux.zip
unzip -o chrome-linux.zip -d $HOME/
rm chrome-linux.zip
INSERT SELECT
Come fare con una query unica una insert di una select.
INSERT INTO tblSending(id_newsletter, id_cliente, stato)
SELECT '1', '2', '42'
SELECT '1', '2', '42'