Zionetrix::Git
Repositories
Help
Report an Issue
cinememe
Code
Commits
Branches
Tags
Search
Tree:
b21ea09
Branches
Tags
master
cinememe
functions.php
Initial commit
Benjamin Renard
commited
b21ea09
at 2015-01-04 23:39:08
functions.php
Blame
History
Raw
<?php function day2int($day,$inv=false) { $days=array( 'lun' => 1, 'mar' => 2, 'mer' => 3, 'jeu' => 4, 'ven' => 5, 'sam' => 6, 'dim' => 7, ); if ($inv) { foreach($days as $d => $i) if ($day==$i) return $d; return false; } else { return (isset($days[$day])?$days[$day]:false); } } function group_days($movies) { $ret=array(); foreach($movies as $m => $days) { //echo $m."\n"; $times=array(); $ret[$m]=array(); foreach ($days as $d => $hs) { foreach ($hs as $h) { if (!isset($times[$h])) { $times[$h]=array(); } $times[$h][]=$d; } } foreach($times as $h => $days) { $f=null; $l=null; $ps=array(); //echo "$m - $h : ".implode('-',$days)."\n"; foreach(array(3,4,5,6,7,1,2,0) as $d) { $day=day2int($d,1); //echo "$h : $day ?\n"; if (in_array($day,$days)) { if ($f==null) { //echo "$h : debut $day\n"; $f=$day; } //else echo "$day : on continue\n"; $prev=$day; } elseif ($f!=null) { //echo "$h : fin $prev\n"; $l=$prev; if ($f==$l) $ps[]=$f; else $ps[]="$f-$l"; $f=null; $l=null; } } //echo "$m - $h => ".implode('&',$ps)."\n"; foreach($ps as $p) { if (!isset($ret[$m][$p])) { $ret[$m][$p]=array(); } $ret[$m][$p][]=$h; } } } return $ret; } function withoutAccents($string){ $replaceAccent = Array( "à" => "a", "á" => "a", "â" => "a", "ã" => "a", "ä" => "a", "ç" => "c", "è" => "e", "é" => "e", "ê" => "e", "ë" => "e", "ì" => "i", "í" => "i", "î" => "i", "ï" => "i", "ñ" => "n", "ò" => "o", "ó" => "o", "ô" => "o", "õ" => "o", "ö" => "o", "ù" => "u", "ú" => "u", "û" => "u", "ü" => "u", "ý" => "y", "ÿ" => "y", "À" => "A", "Á" => "A", "Â" => "A", "Ã" => "A", "Ä" => "A", "Ç" => "C", "È" => "E", "É" => "E", "Ê" => "E", "Ë" => "E", "Ì" => "I", "Í" => "I", "Î" => "I", "Ï" => "I", "Ñ" => "N", "Ò" => "O", "Ó" => "O", "Ô" => "O", "Õ" => "O", "Ö" => "O", "Ù" => "U", "Ú" => "U", "Û" => "U", "Ü" => "U", "Ý" => "Y" ); return strtr($string, $replaceAccent); }