Skip to content

Instantly share code, notes, and snippets.

View dev-hpjsolutions's full-sized avatar

dev-hpjsolutions

View GitHub Profile
@dev-hpjsolutions
dev-hpjsolutions / erreur error affichage
Created January 13, 2014 18:26
php config error pour les joomla
error_reporting = E_ALL & ~E_STRICT & ~E_DEPRECATED & ~E_WARNING
@dev-hpjsolutions
dev-hpjsolutions / obtenir la première image répertoire
Created July 17, 2013 16:26
obtenir la première image d'un répertoire
function get_nom_image($dirname){
$ext = array("jpg", "png", "jpeg", "gif", "JPG", "PNG", "GIF", "JPEG");
$imageName='';
if($handle = opendir($dirname))
{
while(false!== ($file = readdir($handle)))
{
if(strstr($file, "." . $ext[$i])!= '.' && strstr($file, "." . $ext[$i])!= '..')
{
break;
par mois
where MONTH(a.created) = '.$mois.'
@dev-hpjsolutions
dev-hpjsolutions / browser.php
Created June 16, 2013 15:56
Detect browser language
function get_client_language($availableLanguages, $default='en'){
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$langs=explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($langs as $value){
$choice=substr($value,0,2);
if(in_array($choice, $availableLanguages)){
return $choice;
}
}
@dev-hpjsolutions
dev-hpjsolutions / error.php
Created June 16, 2013 15:55
Email error log
<?php
// Our custom error handler
function nettuts_error_handler($number, $message, $file, $line, $vars){
$email = "
<p>An error ($number) occurred on line
<strong>$line</strong> and in the <strong>file: $file.</strong>
<p> $message </p>";
$email .= "<pre>" . print_r($vars, 1) . "</pre>";
@dev-hpjsolutions
dev-hpjsolutions / Query : distance
Created June 16, 2013 15:54
Calculate distance between two points
<?php
// Permet d'obtenir les entrés contenu dans un rayon ($within)
$latitude = 45.545421;
$longitude = -73.59288;
$within = 100;
$query = "
SELECT `zip_code`, (6371 * acos(cos(radians($latitude)) * cos(radians(`lat`)) * cos(radians(`long`) - radians($longitude)) + sin(radians($latitude)) * sin(radians(`lat`))))
AS `distance`
@dev-hpjsolutions
dev-hpjsolutions / sanitize.php
Created June 16, 2013 15:52
Sanitize database input
function cleanInput($input) {
$search = array(
'@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments
);
$output = preg_replace($search, '', $input);
return $output;