Forked from Sanix-Darker/[PHP] Simples amazing PHP fonctions
Created
April 12, 2018 03:05
-
-
Save SANGED/274f32dd7cd66d95103e40736bca58b1 to your computer and use it in GitHub Desktop.
[PHP] Simples amazing PHP fonctions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function InsertOrNot($BD){ // Permet de savoir si oui ou non, un truc a ete inserer dans la base de donnees ou pas! | |
$stmt = $BD->query("SELECT LAST_INSERT_ID()"); | |
$lastId = $stmt->fetch(PDO::FETCH_NUM); | |
$lastId = $lastId[0]; | |
if($lastId>0){ | |
echo "<center><i class=\"green\"><i class=\"fa fa-check\"></i> Opération éffectuée<i></center>"; | |
}else{ | |
echo "<center><i class=\"red\"><i class=\"fa fa-times\"></i>Erreur détectée<i></center>"; | |
} | |
} | |
function DeleteFileIfExist($folder,$Image){ // Pour la suppression d'un fichier | |
if(file_exists($folder.$Image) && is_file($folder.$Image)){ | |
chmod($folder.$Image, 0666); // On definit le Chmod pour les permissions de suppression | |
unlink($folder.$Image); | |
} | |
} | |
function Uploadlefichier($folder,$FILES){ // Pour upload une Image | |
$image = ""; | |
$rand = rand(0,99999); | |
if(!is_dir($folder)){ | |
//On creait le dossier s'il n'hexiste pas! | |
mkdir($folder, 0755, true); | |
} | |
$tmp_name = $FILES["tmp_name"]; | |
$name = $FILES["name"]; | |
$img = pathinfo($FILES['name']); | |
$image = "img_".rand($rand,9999999999).$name; | |
move_uploaded_file($tmp_name, $folder.$image); | |
return $image; | |
} | |
// When usin it | |
$image = Uploadlefichier('../site/images/service/',$_FILES["img"]); // pour inserer l'image | |
// Nice!!!! | |
InsertOrNot($BD); | |
function format_date($date){ | |
$utc = new DateTime($date, new DateTimeZone('UTC')); | |
$utc->setTimezone(new DateTimeZone('Africa/Douala')); | |
return $utc->format('d-m-Y à H:i:s');} | |
function format_dateToTime($date){ | |
$utc = new DateTime($date, new DateTimeZone('UTC')); | |
$utc->setTimezone(new DateTimeZone('Africa/Douala')); | |
return $utc->format('H:i');} | |
function customformat_date($date){ | |
$utc = new DateTime($date, new DateTimeZone('UTC')); | |
$utc->setTimezone(new DateTimeZone('Africa/Douala')); | |
return $utc->format('d-F-Y à H:i:s');} | |
function format_dateDate($date){ | |
$utc = new DateTime($date, new DateTimeZone('UTC')); | |
$utc->setTimezone(new DateTimeZone('Africa/Douala')); | |
return $utc->format('d-m-Y');} | |
function getConvertFileSize($path){ | |
$bytes = sprintf('%u', filesize($path)); | |
if ($bytes > 0) | |
{ | |
$unit = intval(log($bytes, 1024)); | |
$units = array('B', 'KB', 'MB', 'GB'); | |
if (array_key_exists($unit, $units) === true) | |
{ | |
return sprintf('%d %s', $bytes / pow(1024, $unit), $units[$unit]); | |
} | |
} | |
return $bytes; | |
} | |
function getTagExpression( $str) { | |
preg_match('/#(.*?)Z/', $str, $matches); | |
return $matches; | |
} | |
function getTagValues($tag, $str) { | |
$re = sprintf("/\{(%s)\}(.+?)\{\/\\1\}/", preg_quote($tag)); | |
preg_match_all($re, $str, $matches); | |
return $matches[2]; | |
} | |
function MakeUrls($str){ | |
$find=array('`((?:https?|ftp)://\S+[[:alnum:]]/?)`si','`((?<!//)(www\.\S+[[:alnum:]]/?))`si'); | |
$replace=array('<a href="$1" target="_blank">$1</a>', '<a href="http://$1" target="_blank">$1</a>'); | |
return preg_replace($find,$replace,$str); | |
} | |
function getRelativeTime($date) { //Mon incroyable Fonction de Date | |
// Déduction de la date donnée à la date actuelle | |
$utc = new DateTime($date, new DateTimeZone('Africa/Douala')); | |
$utc->setTimezone(new DateTimeZone('Africa/Douala')); | |
$date = $utc->format('Y-m-d H:i:s'); | |
$diff = time() - strtotime($date); | |
if($diff == 0) { | |
return 'maintenant'; | |
} elseif($diff > 0) { | |
$day_diff = floor($diff / 86400); | |
if($day_diff == 0) { | |
if($diff < 60) return 'il y\'a un instant'; | |
if($diff < 120) return 'il y\'a une minute'; | |
if($diff < 3600) return 'il y\'a '.floor($diff / 60) . ' minutes'; | |
if($diff < 7200) return 'il y\'a une heure'; | |
if($diff < 86400) return 'il y\'a '.floor($diff / 3600) . ' heures'; | |
} | |
if($day_diff == 1) { return 'Hier'; } | |
if($day_diff < 7) { return 'il y\'a '.$day_diff . ' jours'; } | |
if($day_diff < 31) { return 'il y\'a '.ceil($day_diff / 7) . ' semaines'; } | |
if($day_diff < 60) { return 'le mois passé'; } | |
return date('F Y', $ts); | |
} else { | |
$diff = abs($diff); | |
$day_diff = floor($diff / 86400); | |
if($day_diff == 0) { | |
if($diff < 120) { return 'dans une minute'; } | |
if($diff < 3600) { return 'dans ' . floor($diff / 60) . ' minutes'; } | |
if($diff < 7200) { return 'dans une heure'; } | |
if($diff < 86400) { return 'dans ' . floor($diff / 3600) . ' heures'; } | |
} | |
if($day_diff == 1) { return 'Demain'; } | |
if($day_diff < 4) { return date('l', $ts); } | |
if($day_diff < 7 + (7 - date('w'))) { return 'La semaine prochaine'; } | |
if(ceil($day_diff / 7) < 4) { return 'dans ' . ceil($day_diff / 7) . ' semaines'; } | |
if(date('n', $ts) == date('n') + 1) { return 'le mois prochain'; } | |
return date('F Y', $ts); | |
} | |
} | |
function format_date3($date){ | |
$date=explode('-',(explode(' ', $date)[0])); | |
$annee=$date[0]; $jour=$date[2]; $mois=$date[1]; | |
$listemois= array('','Jan','Fev','Mars','Avr','Mai','Juin','Juil','Août','Sept','Oct','Nov','Dec'); | |
$newmois=$listemois[($mois+0)]; | |
return $jour." ".$newmois." ".$annee; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment