.
fonctions
Détecter les requette en AJAX
function is_ajax_request(){
return !(empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest');
}
fonctions php
<iframe width="100%" height="254" src="http://snipet.teknotit.com/index.php?embed=54409b4bdb4de" type="text/html"></iframe>
Texte seul - Permalink - Snippet public posté le 17/10/2014
Utilisation image Gravatars
/******************
*@email - Email address to show gravatar for
*@size - size of gravatar
*@default - URL of default gravatar to use
*@rating - rating of Gravatar(G, PG, R, X)
*/
function show_gravatar($email, $size, $default, $rating)
{
echo '<img src="http://www.gravatar.com/avatar.php?gravatar_id='.md5($email).
'&default='.$default.'&size='.$size.'&rating='.$rating.'" width="'.$size.'px"
height="'.$size.'px" />';
}
Api fonctions php
<iframe width="100%" height="416" src="http://snipet.teknotit.com/index.php?embed=54409a8f98ac5" type="text/html"></iframe>
Texte seul - Permalink - Snippet public posté le 17/10/2014
Force download - Forcer le download d'un fichier
/********************
*@file - path to file
*/
function force_download($file)
{
if ((isset($file))&&(file_exists($file))) {
header("Content-length: ".filesize($file));
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $file . '"');
readfile("$file");
} else {
echo "No file selected";
}
}
fichier fonctions php
<iframe width="100%" height="452" src="http://snipet.teknotit.com/index.php?embed=54409a0e1a97d" type="text/html"></iframe>
Texte seul - Permalink - Snippet public posté le 17/10/2014
Minimal post slug
function create_slug($string){
$slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
return $slug;
}
fonctions php
<iframe width="100%" height="254" src="http://snipet.teknotit.com/index.php?embed=544099c382072" type="text/html"></iframe>
Texte seul - Permalink - Snippet public posté le 17/10/2014
Supression répertoire avec son contenu
/*****
*@dir - Directory to destroy
*@virtual[optional]- whether a virtual directory
*/
function destroyDir($dir, $virtual = false)
{
$ds = DIRECTORY_SEPARATOR;
$dir = $virtual ? realpath($dir) : $dir;
$dir = substr($dir, -1) == $ds ? substr($dir, 0, -1) : $dir;
if (is_dir($dir) && $handle = opendir($dir))
{
while ($file = readdir($handle))
{
if ($file == '.' || $file == '..')
{
continue;
}
elseif (is_dir($dir.$ds.$file))
{
destroyDir($dir.$ds.$file);
}
else
{
unlink($dir.$ds.$file);
}
}
closedir($handle);
rmdir($dir);
return true;
}
else
{
return false;
}
}
fonctions php repertoire
<iframe width="100%" height="830" src="http://snipet.teknotit.com/index.php?embed=544098c4c60d1" type="text/html"></iframe>
Texte seul - Permalink - Snippet public posté le 17/10/2014
Tronquer un texte (extrait)
function truncate($string, $length = 44, $etc = '...', $break_words = false, $middle = false)
{
if ($length == 0)
return '';
if (strlen($string) > $length) {
$length -= min($length, strlen($etc));
if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1));
}
if (!$middle) {
return substr($string, 0, $length) . $etc;
} else {
return substr($string, 0, $length / 2) . $etc . substr($string, - $length / 2);
}
} else {
return $string;
}
}
fonctions php
<iframe width="100%" height="524" src="http://snipet.teknotit.com/index.php?embed=5440951a6a642" type="text/html"></iframe>
Texte seul - Permalink - Snippet public posté le 17/10/2014
Alternative a file_get_content pour les restriction des hébergeurs...
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
fonctions php
<iframe width="100%" height="398" src="http://snipet.teknotit.com/index.php?embed=544094a3a27ba" type="text/html"></iframe>
Texte seul - Permalink - Snippet public posté le 17/10/2014
Supression des espace et des espace en double
function clean_trim($str) {
// First remove the leading/trailing whitespace
$str = trim($str);
// Now remove any doubled-up whitespace
$str = preg_replace('/\s(?=\s)/', '', $str);
// Finally, replace any non-space whitespace, with a space
$str = preg_replace('/[\n\r\t]/', ' ', $str);
return $str;
}
fonctions php
<iframe width="100%" height="362" src="http://snipet.teknotit.com/index.php?embed=544093fdebc42" type="text/html"></iframe>
Texte seul - Permalink - Snippet public posté le 17/10/2014
Random String
/**
* generate_rand
*
* chaine de caractère aléatoire.
*
* @param length nombre de caractères
*/
function generate_rand($length=4) {
$chn = '';
for ($i = 1; $i <= $length; $i++)
$chn .=chr(floor(rand(0, 25) + 97));
return $chn;
}
aleatoire fonctions php
<iframe width="100%" height="434" src="http://snipet.teknotit.com/index.php?embed=5440918b74687" type="text/html"></iframe>
Texte seul - Permalink - Snippet public posté le 17/10/2014
Chaîne de caractère aléatoire lisible
/**************
* Générer une chaîne de caractère aléatoire
*@length - longueur de chaîne aléatoire (doit être divisible par 2)
**************/
function readable_random_string($length = 6){
$conso=array("b","c","d","f","g","h","j","k","l",
"m","n","p","r","s","t","v","w","x","y","z");
$vocal=array("a","e","i","o","u");
$password="";
srand ((double)microtime()*1000000);
$max = $length/2;
for($i=1; $i<=$max; $i++)
{
$password.=$conso[rand(0,19)];
$password.=$vocal[rand(0,4)];
}
return $password;
}
aleatoire fonctions php
<iframe width="100%" height="524" src="http://snipet.teknotit.com/index.php?embed=54408b8d1dbdb" type="text/html"></iframe>
Texte seul - Permalink - Snippet public posté le 17/10/2014