<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Darklg Blog &#187; Développement PHP / MySQL</title> <atom:link href="http://blog.darklg.fr/category/developpement-php-mysql/feed/" rel="self" type="application/rss+xml" /><link>http://blog.darklg.fr</link> <description>Intégration, développement web, SEO, caféine</description> <lastBuildDate>Tue, 31 Aug 2010 18:28:36 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator> <item><title>Un Système de grilles/grid avec CSS &amp; PHP</title><link>http://blog.darklg.fr/339/systeme-grille-grid-css-php/</link> <comments>http://blog.darklg.fr/339/systeme-grille-grid-css-php/#comments</comments> <pubDate>Tue, 16 Mar 2010 22:38:22 +0000</pubDate> <dc:creator>darklg</dc:creator> <category><![CDATA[Développement PHP / MySQL]]></category> <category><![CDATA[Intégration xHTML / CSS]]></category> <category><![CDATA[css]]></category> <category><![CDATA[grid]]></category> <category><![CDATA[grilles]]></category> <category><![CDATA[php]]></category><guid
isPermaLink="false">http://blog.darklg.fr/?p=339</guid> <description><![CDATA[J&#8217;utilise depuis quelques mois un système de grilles léger et efficace : Le 1kb CSS GRID. Malheureusement, la version proposée sur le blog demande une reconfiguration cas par cas, et la version générée par le site dédié, demandait un retour au site pour chaque nouveau projet. J&#8217;ai donc décidé de monter un bout de code ... <a
href="http://blog.darklg.fr/339/systeme-grille-grid-css-php/">lire la suite</a>]]></description> <content:encoded><![CDATA[<p>J&#8217;utilise depuis quelques mois un système de grilles léger et efficace :<br
/> <a
href="http://www.usabilitypost.com/2009/05/29/the-1kb-css-grid-part-1/">Le 1kb CSS GRID</a>.</p><p>Malheureusement, la version  proposée sur le blog demande une reconfiguration cas par cas, et la version générée par le <a
href="http://www.1kbgrid.com/">site dédié</a>, demandait un retour au site pour chaque nouveau projet. J&#8217;ai donc décidé de monter un bout de code pour automatiser la création de grilles.<br
/> Attention, je ne gère pas de marges internes, ces dernières sont générées par les éléments contenus dans ces grilles. C&#8217;est mal, je sais.</p><p>On definit le nombre de colonnes et leur largeur par défaut.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Version A : nb_colonnes * largeur_colonne = largeur_ligne</span>
<span style="color: #000088;">$grid_nb_colonnes</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">12</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$grid_largeur</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">;</span></pre></div></div><p>Il est évidemment possible de définir la largeur totale d&#8217;une ligne :</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Version B : largeur_ligne / nb_colonnes = largeur_colonne</span>
<span style="color: #000088;">$grid_largeur_ligne</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">960</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$grid_largeur</span> <span style="color: #339933;">=</span> <span style="color: #990000;">round</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$grid_largeur_ligne</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$grid_nb_colonnes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Faites toutefois attention à utiliser des valeurs multiples, afin d&#8217;éviter une colonne trop petite, ou trop grande.</p><p>On génère ensuite une propriété pour chaque largeur de grille</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;=</span><span style="color: #000088;">$grid_nb_colonnes</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'.grid_'</span><span style="color: #339933;">.</span><span style="color: #000088;">$i</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'{width:'</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">*</span><span style="color: #000088;">$grid_largeur</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'px;} '</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></pre></div></div><p>On affiche les propriétés de gestion de lignes et colonnes</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'.column{float:left;overflow:hidden;display:inline;}'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'.row{width:'</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$grid_nb_colonnes</span><span style="color: #339933;">*</span><span style="color: #000088;">$grid_largeur</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'px;overflow:hidden;margin:0 auto;}'</span><span style="color: #339933;">;</span></pre></div></div><p>Et voilà <img
src='http://blog.darklg.fr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> c&#8217;est évidemment utilisable dans mon <a
href="http://blog.darklg.fr/328/compresser-ranger-css-php/">système de compression CSS via PHP</a>, à condition de charger le contenu dans la variable $retour_css au lieu d&#8217;afficher le contenu via <strong>echo</strong>, et de l&#8217;insérer juste avant l&#8217;appel à la fonction compress();. La configuration des largeurs et colonnes peut être par contre montée en haut du script, pour plus de confort <img
src='http://blog.darklg.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p>Note : Le bout de code est sous <a
href="http://fr.wikipedia.org/wiki/WTF_Public_License">licence WTFPL</a>, mais un lien, un merci ou <a
href="https://www.amazon.fr/wishlist/1RVCWI76NZASX">un cadeau</a> (Sait-on jamais qu&#8217;un puissant mécène qui souhaite mon bonheur me lise) sont appréciés.</p><hr
/><p
style="font-size : 10px;"> Un article publi&eacute; sur <a
href="http://blog.darklg.fr">Darklg Blog</a> &copy; 2010<br
/> Lien vers l'article original : <a
href="http://blog.darklg.fr/339/systeme-grille-grid-css-php/">Un Système de grilles/grid avec CSS &amp; PHP</a><br
/> <a
rel="external nofollow" href="http://minurl.fr/?twitter&amp;titrelien=Darklg+Blog+%3A+Un+Syst%C3%A8me+de+grilles%2Fgrid+avec+CSS+%26amp%3B+PHP&amp;url=http://blog.darklg.fr/339/systeme-grille-grid-css-php/" title="Envoyer vers Twitter, avec MinURL !">Partager cet article sur Twitter</a></p>]]></content:encoded> <wfw:commentRss>http://blog.darklg.fr/339/systeme-grille-grid-css-php/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Compresser et ranger son CSS avec PHP.</title><link>http://blog.darklg.fr/328/compresser-ranger-css-php/</link> <comments>http://blog.darklg.fr/328/compresser-ranger-css-php/#comments</comments> <pubDate>Sun, 21 Feb 2010 17:19:07 +0000</pubDate> <dc:creator>darklg</dc:creator> <category><![CDATA[Développement PHP / MySQL]]></category> <category><![CDATA[Intégration xHTML / CSS]]></category> <category><![CDATA[astuce]]></category> <category><![CDATA[compresser]]></category> <category><![CDATA[css]]></category> <category><![CDATA[php]]></category><guid
isPermaLink="false">http://blog.darklg.fr/?p=328</guid> <description><![CDATA[Voici une méthode permettant de compresser des CSS, que j&#8217;utilise depuis quelques mois. Elle répond à plusieurs impératifs : Réduire le nombre de CSS chargés au minimum, pour économiser les requêtes HTTP. Permettre de créer des fichiers CSS à la volée, sans code php à l&#8217;interieur, et de les diviser le plus possible. Compresser le ... <a
href="http://blog.darklg.fr/328/compresser-ranger-css-php/">lire la suite</a>]]></description> <content:encoded><![CDATA[<p>Voici une méthode permettant de compresser des CSS, que j&#8217;utilise depuis quelques mois. Elle répond à plusieurs impératifs :</p><ul><li>Réduire le nombre de CSS chargés au minimum, pour économiser les requêtes HTTP.</li><li>Permettre de créer des fichiers CSS à la volée, sans code php à l&#8217;interieur, et de les diviser le plus possible.</li><li>Compresser le résultat.</li><li>Mettre en cache la version compressée, qui sera servie au visiteur.</li></ul><p>Cette méthode est grandement inspirée de l&#8217;article sur la <a
href="http://www.catswhocode.com/blog/3-ways-to-compress-css-files-using-php">compression des CSS chez CatsWhoCode</a>, que j&#8217;ai décortiqué pendant un bout de temps <img
src='http://blog.darklg.fr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>On fera donc appel à ces fichiers :</p><ul><li>style.php : appelé pour créer la page, mais qui transmet également les instructions CSS.</li><li>style-min.css : Le CSS final, appelé par la version du site.</li><li>style/ : Le sous dossier contenant tous vos CSS.</li></ul><p>Les éventuelles images devront être dans le même répertoire que style.php.</p><p>Voici donc le code commenté de style.php :</p><p>On déclare le contenu comme étant du CSS, pour être sûr de son interpretation.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: text/css&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Ensuite, il faut inclure les CSS, que l&#8217;on va trier dans l&#8217;ordre alphabétique, pour permettre d&#8217;éventuels hacks, et surtout une idée de l&#8217;ordre des instructions.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// On cree une variable de retour pour contenir le CSS.</span>
<span style="color: #000088;">$retour_css</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// On parcourt le sous-dossier style/</span>
<span style="color: #000088;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #990000;">opendir</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;style/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fichiers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// On ajoute chaque fichier à un tableau 'fichiers'</span>
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichier</span> <span style="color: #339933;">=</span> <span style="color: #990000;">readdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichier</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;.&quot;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$fichier</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;..&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$fichiers</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'style/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$fichier</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
<span style="color: #990000;">closedir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Tri par ordre alphabetique des fichiers</span>
<span style="color: #990000;">asort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichiers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// inclusion des fichiers ... dans l'ordre</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichiers</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$fichier</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000088;">$retour_css</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichier</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>La fonction compress() va agir sur plusieurs points :</p><ul><li>Retirer les caractères &laquo;&nbsp;inutiles&nbsp;&raquo;, comme les commentaires, tabulations, et transformer les espaces multiples en espaces simples, etc.</li><li>Permettre la mise en place d&#8217;un léger système de variables. Utile si vous avez beaucoup de fichiers <img
src='http://blog.darklg.fr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></li></ul><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> compress<span style="color: #009900;">&#40;</span><span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$variables_css</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'COULEUR1'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'#003366'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'COULEUR2'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'#336699'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'FONT1'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Georgia, serif'</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// On remplace les variables par leur valeur</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$variables_css</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$code_variable</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$valeur</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'{'</span><span style="color: #339933;">.</span><span style="color: #000088;">$code_variable</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'}'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$valeur</span><span style="color: #339933;">,</span> <span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Suppression des commentaires</span>
	<span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'!/\*[^*]*\*+([^/][^*]*\*+)*/!'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Suppression des tabulations, espaces multiples, retours à la ligne, etc.</span>
	<span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'  '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'	 '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'	 '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Suppression des derniers espaces inutiles</span>
	<span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' { '</span><span style="color: #339933;">,</span><span style="color: #0000ff;">' {'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'{ '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'{'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' } '</span><span style="color: #339933;">,</span><span style="color: #0000ff;">' }'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'} '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'}'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' : '</span><span style="color: #339933;">,</span><span style="color: #0000ff;">' :'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">': '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">':'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$buffer</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Compression du CSS</span>
<span style="color: #000088;">$retour_css</span> <span style="color: #339933;">=</span> compress<span style="color: #009900;">&#40;</span><span style="color: #000088;">$retour_css</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Enfin, nous allons mettre en cache le contenu de la variable $retour_css, et l&#8217;afficher, pour les tests.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Mise en cache du fichier style-min.css</span>
<span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'style-min.css'</span><span style="color: #339933;">,</span><span style="color: #000088;">$retour_css</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// On affiche le contenu compressé</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$retour_css</span><span style="color: #339933;">;</span></pre></div></div><p>Vous pouvez créer autant de fichiers CSS que vous le désirez dans le sous-dossier style/, afin de séparer couleurs, tailles, réglages de base, Reset CSS et autres grilles.</p><p>Vous m&#8217;avez lu jusqu&#8217;ici ? Woah <img
src='http://blog.darklg.fr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Apprenez donc que ce code est sous licence <a
href="http://fr.wikipedia.org/wiki/WTF_Public_License">WTFPL</a>, qu&#8217;un lien vers cet article sera accueilli avec grand bonheur, et qu&#8217;un commentaire constructif le sera également <img
src='http://blog.darklg.fr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><hr
/><p
style="font-size : 10px;"> Un article publi&eacute; sur <a
href="http://blog.darklg.fr">Darklg Blog</a> &copy; 2010<br
/> Lien vers l'article original : <a
href="http://blog.darklg.fr/328/compresser-ranger-css-php/">Compresser et ranger son CSS avec PHP.</a><br
/> <a
rel="external nofollow" href="http://minurl.fr/?twitter&amp;titrelien=Darklg+Blog+%3A+Compresser+et+ranger+son+CSS+avec+PHP.&amp;url=http://blog.darklg.fr/328/compresser-ranger-css-php/" title="Envoyer vers Twitter, avec MinURL !">Partager cet article sur Twitter</a></p>]]></content:encoded> <wfw:commentRss>http://blog.darklg.fr/328/compresser-ranger-css-php/feed/</wfw:commentRss> <slash:comments>49</slash:comments> </item> <item><title>Redirection 301 &#8211; .htaccess et PHP</title><link>http://blog.darklg.fr/319/redirection-301-htaccess-php/</link> <comments>http://blog.darklg.fr/319/redirection-301-htaccess-php/#comments</comments> <pubDate>Mon, 28 Dec 2009 12:24:05 +0000</pubDate> <dc:creator>darklg</dc:creator> <category><![CDATA[Développement PHP / MySQL]]></category> <category><![CDATA[Référencement]]></category> <category><![CDATA[htaccess]]></category> <category><![CDATA[php]]></category> <category><![CDATA[redirection]]></category><guid
isPermaLink="false">http://blog.darklg.fr/?p=319</guid> <description><![CDATA[Accès direct : Redirection 301 via PHP Redirection 301 via htaccess ( Apache ) Il vous arrive peut-être de devoir changer le nom de domaine ou la structure d&#8217;un site. Un immonde /index.php?mapage=outils&#38;souspage=whois se transformant ( grâce à l&#8217;url rewriting &#8230; ou non ) en un sympathique /outils/whois.htm. Un nom de domaine peut également être ... <a
href="http://blog.darklg.fr/319/redirection-301-htaccess-php/">lire la suite</a>]]></description> <content:encoded><![CDATA[<p>Accès direct :</p><ul><li><a
href="http://blog.darklg.fr/319/redirection-301-htaccess-php/#redirection-php">Redirection 301 via PHP</a></li><li><a
href="http://blog.darklg.fr/319/redirection-301-htaccess-php/#redirection-htaccess">Redirection 301 via htaccess ( Apache )</a></li></ul><p>Il vous arrive peut-être de devoir changer le <strong>nom de domaine</strong> ou la structure d&#8217;un site. Un immonde <span
style="color: #333399;">/index.php?mapage=outils&amp;souspage=whois</span> se transformant ( grâce à l&#8217;url rewriting &#8230; ou non ) en un sympathique <span
style="color: #333399;">/outils/whois.htm</span>. Un nom de domaine peut également être remplacé par un plus clair / court / mémorisable / lisible.</p><p>Les avantages sont connus : un <strong>meilleur référencement</strong>, une URL plus claire et plus facile à mémoriser ou à retrouver dans ses favoris/marque-pages, etc.</p><p>Mais cette méthode comporte également certains inconvénients : Les moteurs de recherche se &laquo;&nbsp;souviennent&nbsp;&raquo; de l&#8217;<strong>ancienne URL</strong> et risquent de considérer la <strong>nouvelle</strong> comme un doublon, des liens peuvent exister vers l&#8217;ancienne page, et les webmasters de ces sites peuvent ne pas répondre &#8230; ou ne plus tenir à jour leur site, et plus important : des favoris/marque-pages de visiteurs peuvent mener vers une page d&#8217;erreur 404.</p><p>C&#8217;est pourquoi il est très important de maintenir une <strong>cohérence</strong> entre l&#8217;ancienne page et la nouvelle, en mettant en place une <strong>redirection</strong> 301 ( définitive ).</p><p>Note : Je n&#8217;aborderais pas la <strong>redirection 302</strong> (redirection temporaire), parce qu&#8217;elle n&#8217;est vraiment utile que dans de rares cas, et est souvent mal utilisée. Mais c&#8217;est un avis personnel qui n&#8217;engage que moi.</p><p>J&#8217;utilise deux techniques différentes, selon les cas de figure, donc à utiliser selon votre préférence : <strong>htaccess</strong> ou <strong>PHP</strong>.</p><h3 id="redirection-php">Redirection 301 via PHP</h3><p>Avant tout envoi de code html / css (même les espaces et tabulations), collez ce code :</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location: http://www.monsite.com/nouvelleurl.htm'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">301</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div><p>Notes :</p><ul><li>J&#8217;utilise toujours des URL absolues (avec http: //mondomaine.com avant) pour être sûr de la destination.</li><li>Les deux derniers paramètres ( <strong>true</strong> et <strong>301</strong> ) sont obligatoires pour un bon fonctionnement.</li><li>Un espace après &quot;<strong>location</strong>&quot;, pas avant !</li><li>Le exit(); permet d&#8217;arrêter votre script juste après, et de ne pas envoyer de données. Au choix.</li><li>J&#8217;utilise cette méthode pour rediriger une URL dynamique ou indésirable vers une autre, en complément d&#8217;un <a
href="http://www.google.com/support/webmasters/bin/answer.py?hl=fr&#038;answer=139394">lien canonical</a>.</li></ul><h3 id="redirection-htaccess">Redirection 301 via .htaccess ( Apache )</h3><p>Dans un fichier .htaccess créé à la racine de votre site ( généralement le même dossier que le index.php ou index.htm principal ), collez ce code :</p><div
class="wp_syntax"><div
class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">RedirectPermanent</span> /ancienneurl.php http://www.monsite.com/nouvelleurl.htm</pre></div></div><p>Notes :</p><ul><li>La casse de la commande peut changer selon les scripts, mais je me base sur la <a
href="http://www.apachefrance.com/Manuels/Apache_1.3_VF/mod/mod_alias.html#redirectperm">syntaxe donnée par le manuel Apache</a>(Serveur Web). Bon à savoir, cette page peut également vous fournir d&#8217;autres redirections plus complexes (mais bien utiles) comme RedirectMatch.</li><li>Encore une fois, une URL absolue pour la destination.</li><li>Le module Apache mod_alias.c doit être activé. Mais par défaut &#8230; c&#8217;est fait. Si le bout de code ne marche vraiment pas, contactez votre hébergeur.</li></ul><p><strong>Bonne redirection à tous !</strong></p><p>PS : évidemment, mes méthodes ne sont sûrement pas les meilleures. Mais si vous avez mieux, les commentaires sont là pour ça <img
src='http://blog.darklg.fr/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> .<br
/> PS2 : Ce blog tourne vraiment au bloc-notes et aide mémoire. Mais si vous lisez cette phrase, c&#8217;est que ça vous a intéressé, oui ? ( non ? Partez pas, quoi <img
src='http://blog.darklg.fr/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> )</p><hr
/><p
style="font-size : 10px;"> Un article publi&eacute; sur <a
href="http://blog.darklg.fr">Darklg Blog</a> &copy; 2010<br
/> Lien vers l'article original : <a
href="http://blog.darklg.fr/319/redirection-301-htaccess-php/">Redirection 301 &#8211; .htaccess et PHP</a><br
/> <a
rel="external nofollow" href="http://minurl.fr/?twitter&amp;titrelien=Darklg+Blog+%3A+Redirection+301+%26%238211%3B+.htaccess+et+PHP&amp;url=http://blog.darklg.fr/319/redirection-301-htaccess-php/" title="Envoyer vers Twitter, avec MinURL !">Partager cet article sur Twitter</a></p>]]></content:encoded> <wfw:commentRss>http://blog.darklg.fr/319/redirection-301-htaccess-php/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>[PHP] ob_gzhandler compresse vos pages web</title><link>http://blog.darklg.fr/238/php-ob_gzhandler-compresse-vos-pages-web/</link> <comments>http://blog.darklg.fr/238/php-ob_gzhandler-compresse-vos-pages-web/#comments</comments> <pubDate>Wed, 25 Feb 2009 13:32:15 +0000</pubDate> <dc:creator>darklg</dc:creator> <category><![CDATA[Développement PHP / MySQL]]></category> <category><![CDATA[gzip]]></category> <category><![CDATA[ob_gzhandler]]></category> <category><![CDATA[php]]></category><guid
isPermaLink="false">http://blog.darklg.fr/?p=238</guid> <description><![CDATA[J&#8217;utilise depuis quelques temps ce petit bout de code pour compresser à la volée les données qui sont envoyées sur mes sites. ( En gros, le HTML / xHTML que vous recevez ) : &#60;?php ob_start&#40;&#34;ob_gzhandler&#34;&#41;; ?&#62; Ce dernier doit être inséré avant tout envoi de code html / données quelconques. Malheureusement, j&#8217;avais pris la ... <a
href="http://blog.darklg.fr/238/php-ob_gzhandler-compresse-vos-pages-web/">lire la suite</a>]]></description> <content:encoded><![CDATA[<p>J&#8217;utilise depuis quelques temps ce petit bout de code pour compresser à la volée les données qui sont envoyées sur mes sites. ( En gros, le HTML / xHTML que vous recevez ) :</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ob_gzhandler&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div><p>Ce dernier <strong>doit</strong> être inséré avant tout envoi de code html / données quelconques.</p><p>Malheureusement, j&#8217;avais pris la mauvaise habitude de l&#8217;insérer au tout début de mon code source, à la suite de la balise ouvrante &nbsp;&raquo; &lt;?php &laquo;&nbsp;, afin de ne pas l&#8217;oublier, au même titre qu&#8217;un sempiternel &nbsp;&raquo; session_start(); &laquo;&nbsp;. Le temps de génération d&#8217;une page / envoi au client sur <a
href="http://minurl.fr">MinURL</a> prenait alors en moyenne 200 ms ( sur mon couple connexion / navigateur ).</p><p>Par curiosité, j&#8217;ai décidé de le descendre juste avant l&#8217;envoi du doctype html, donc après l&#8217;exécution de la majorité de mon code, pour atteindre quelque chose de ce style :</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ob_gzhandler&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span></pre></div></div><p>Résultat des courses, le temps de génération de la page est descendu à 100ms ( toujours sur mon couple connexion / navigateur ).</p><p>Pourquoi donc ? Parce que cette fonction n&#8217;a pas eu à guetter les éventuelles données à compresser dans l&#8217;exécution du code ( qui rappelons-le, devrait être séparée de la partie &laquo;&nbsp;affichage&nbsp;&raquo; ). Si un développeur chevronné passe par ici et qu&#8217;il veut donner plus de détails, je les lirais avec plaisir <img
src='http://blog.darklg.fr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>Ne faites donc pas la même erreur &#8211; de débutant &#8211; que moi <img
src='http://blog.darklg.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><hr
/><p
style="font-size : 10px;"> Un article publi&eacute; sur <a
href="http://blog.darklg.fr">Darklg Blog</a> &copy; 2010<br
/> Lien vers l'article original : <a
href="http://blog.darklg.fr/238/php-ob_gzhandler-compresse-vos-pages-web/">[PHP] ob_gzhandler compresse vos pages web</a><br
/> <a
rel="external nofollow" href="http://minurl.fr/?twitter&amp;titrelien=Darklg+Blog+%3A+%5BPHP%5D+ob_gzhandler+compresse+vos+pages+web&amp;url=http://blog.darklg.fr/238/php-ob_gzhandler-compresse-vos-pages-web/" title="Envoyer vers Twitter, avec MinURL !">Partager cet article sur Twitter</a></p>]]></content:encoded> <wfw:commentRss>http://blog.darklg.fr/238/php-ob_gzhandler-compresse-vos-pages-web/feed/</wfw:commentRss> <slash:comments>14</slash:comments> </item> <item><title>Echec et (100%) Mag !</title><link>http://blog.darklg.fr/177/echec-et-100-mag/</link> <comments>http://blog.darklg.fr/177/echec-et-100-mag/#comments</comments> <pubDate>Sat, 06 Dec 2008 09:45:44 +0000</pubDate> <dc:creator>darklg</dc:creator> <category><![CDATA[Bugs du web]]></category> <category><![CDATA[Développement PHP / MySQL]]></category><guid
isPermaLink="false">http://blog.darklg.fr/?p=177</guid> <description><![CDATA[Le site web de la chaîne M6 n&#8217;est pas ce qu&#8217;on peut appeler une réussite en terme d&#8217;ergonomie. En effet, une recherche au sein des archives d&#8217;émissions nous amène sur cette page d&#8217;une utilité flagrante. Impossible de voir les dates des programmes, sauf pour les émissions de fin novembre à fin décembre ( dont les ... <a
href="http://blog.darklg.fr/177/echec-et-100-mag/">lire la suite</a>]]></description> <content:encoded><![CDATA[<p
style="text-align:center;"><a
href="http://www.flickr.com/photos/24327610@N04/3085885837" title="View 'Echec et (100%) Mag !' on Flickr.com"><img
src="http://farm4.static.flickr.com/3145/3085885837_9de945ed42_o.png" alt="Echec et (100%) Mag !" /></a></p><p>Le site web de la chaîne M6 n&#8217;est pas ce qu&#8217;on peut appeler une réussite en terme d&#8217;ergonomie. En effet, une recherche au sein des archives d&#8217;émissions nous amène sur cette page d&#8217;une utilité flagrante. Impossible de voir les dates des programmes, sauf pour les émissions de fin novembre à fin décembre ( dont les pages n&#8217;ont d&#8217;ailleurs aucun contenu ).</p><p>Dommage.</p><p><a
href="http://www.m6.fr/guide-tv/100-mag-jsp.html?id=gdp2_466018&#038;archive=true">Source</a></p><hr
/><p
style="font-size : 10px;"> Un article publi&eacute; sur <a
href="http://blog.darklg.fr">Darklg Blog</a> &copy; 2010<br
/> Lien vers l'article original : <a
href="http://blog.darklg.fr/177/echec-et-100-mag/">Echec et (100%) Mag !</a><br
/> <a
rel="external nofollow" href="http://minurl.fr/?twitter&amp;titrelien=Darklg+Blog+%3A+Echec+et+%28100%25%29+Mag+%21&amp;url=http://blog.darklg.fr/177/echec-et-100-mag/" title="Envoyer vers Twitter, avec MinURL !">Partager cet article sur Twitter</a></p>]]></content:encoded> <wfw:commentRss>http://blog.darklg.fr/177/echec-et-100-mag/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>PHP : fonction iif</title><link>http://blog.darklg.fr/173/php-fonction-iif/</link> <comments>http://blog.darklg.fr/173/php-fonction-iif/#comments</comments> <pubDate>Thu, 04 Dec 2008 16:16:51 +0000</pubDate> <dc:creator>darklg</dc:creator> <category><![CDATA[Développement PHP / MySQL]]></category> <category><![CDATA[fonction]]></category> <category><![CDATA[iif]]></category> <category><![CDATA[php]]></category><guid
isPermaLink="false">http://blog.darklg.fr/?p=173</guid> <description><![CDATA[Voici une fonction que j&#8217;utilise beaucoup, et qui pourra peut-être vous rendre service : La fonction iif(). Cette fonction existe dans de nombreux langages, mais pas en PHP. Une erreur réparée avec cette fonction à copier coller : function iif&#40;$condition,$ok,$nok=''&#41; &#123; return &#40;$condition ? $ok : $nok&#41;; &#125; La fonction iif vous permet tout simplement ... <a
href="http://blog.darklg.fr/173/php-fonction-iif/">lire la suite</a>]]></description> <content:encoded><![CDATA[<p>Voici une fonction que j&#8217;utilise beaucoup, et qui pourra peut-être vous rendre service : La fonction <strong>iif</strong>().<br
/> Cette fonction existe dans de nombreux langages, mais pas en PHP.<br
/> Une erreur réparée avec cette fonction à copier coller :</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> iif<span style="color: #009900;">&#40;</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$ok</span><span style="color: #339933;">,</span><span style="color: #000088;">$nok</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$condition</span> ? <span style="color: #000088;">$ok</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$nok</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p>La fonction <strong>iif</strong> vous permet tout simplement de vérifier une condition à l&#8217;intérieur d&#8217;une ligne de code.<br
/> Exemple :</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Bon '</span><span style="color: #339933;">.</span>iif<span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'h'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">12</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Matin'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Aprem'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' à vous'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Affiche 'Bon Matin à vous' || 'Bon Aprem à vous' selon l'heure de la journée</span></pre></div></div><p>Vous n&#8217;êtes pas obligés de spécifier un résultat si la condition n&#8217;est pas respectée.<br
/> Si cette fonction ne vous sert pas, je saurais au moins où la retrouver :p</p><hr
/><p
style="font-size : 10px;"> Un article publi&eacute; sur <a
href="http://blog.darklg.fr">Darklg Blog</a> &copy; 2010<br
/> Lien vers l'article original : <a
href="http://blog.darklg.fr/173/php-fonction-iif/">PHP : fonction iif</a><br
/> <a
rel="external nofollow" href="http://minurl.fr/?twitter&amp;titrelien=Darklg+Blog+%3A+PHP+%3A+fonction+iif&amp;url=http://blog.darklg.fr/173/php-fonction-iif/" title="Envoyer vers Twitter, avec MinURL !">Partager cet article sur Twitter</a></p>]]></content:encoded> <wfw:commentRss>http://blog.darklg.fr/173/php-fonction-iif/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>[PHP] Erreur : Cannot modify header information : headers already sent by</title><link>http://blog.darklg.fr/136/php-erreur-cannot-modify-header-information/</link> <comments>http://blog.darklg.fr/136/php-erreur-cannot-modify-header-information/#comments</comments> <pubDate>Wed, 22 Oct 2008 16:28:54 +0000</pubDate> <dc:creator>darklg</dc:creator> <category><![CDATA[Développement PHP / MySQL]]></category> <category><![CDATA[erreur]]></category> <category><![CDATA[header]]></category> <category><![CDATA[php]]></category><guid
isPermaLink="false">http://blog.darklg.fr/?p=136</guid> <description><![CDATA[L&#8217;erreur du jour qui m&#8217;a fait frémir : &#171;&#160;Cannot modify header information &#8211; headers already sent by &#160;&#187; Sa cause ? On tente de modifier des entêtes de documents alors que des informations ont déjà été envoyées au client. Pour avoir passé une demi-heure à chercher des solutions valables, voici le processus à suivre pour ... <a
href="http://blog.darklg.fr/136/php-erreur-cannot-modify-header-information/">lire la suite</a>]]></description> <content:encoded><![CDATA[<p>L&#8217;erreur du jour qui m&#8217;a fait frémir : &laquo;&nbsp;<strong>Cannot modify header information &#8211; headers already sent by </strong>&nbsp;&raquo;<br
/> Sa cause ? On tente de modifier des entêtes de documents alors que des informations ont déjà été envoyées au client.</p><p>Pour avoir passé une demi-heure à chercher des solutions valables, voici le processus à suivre pour résoudre ce problème :</p><ol><li>Regarder si aucun echo, espace, ou autre bout de code html n&#8217;existe dans le fichier avant toute fonction de modification d&#8217;entêtes : (<em>header()</em>, <em>setcookie()</em>, <em>session_start()</em>, et autres)</li><li>Dans les fichiers inclus avant l&#8217;appel de votre fonction, vérifier qu&#8217;aucun espace ne s&#8217;est glissé entre des balises PHP.<br
/> Verifier soigneusement le haut de page, avant la premiere balise PHP (&lt;?php), et le bas de page, après la fermeture de la dernière balise PHP.</li><li>Il est possible que l&#8217;entête <strong>X-Powered-By</strong> soit envoyée par PHP. Cette entête contenant uniquement la version de PHP utilisée, vous pouvez la désactiver sans crainte : <a
href="http://blog.darklg.fr/143/php-desactiver-entete-x-powered-by/">Désactiver X-Powered-By</a>.</li></ol><p>Ca ne marche toujours pas ?<br
/> Voici deux solutions, pour deux problèmes différents :</p><ul><li>Vous n&#8217;utilisez que la fonction <em>session_start()</em>, il n&#8217;y a rien au dessus.<br
/> Supprimez la fonction <em>session_start()</em>;<br
/> Ajoutez cette ligne dans votre fichier .htaccess :<br
/> <code>php_value session.auto_start 1</code><br
/> Ou ajoutez cette ligne dans votre fichier php.ini :<br
/> <code>session.auto_start 1</code><br
/> Attention, c&#8217;est une méthode qui est <strong>déconseillée</strong> !</li><li>Tout a été tenté, rien ne marche ?<br
/> Ajoutez tout en haut du fichier PHP appelé la fonction : <em>ob_start();</em><br
/> Ajoutez tout en bas du fichier PHP appelé la fonction :<em> ob_end_flush();</em><br
/> Explication : ob_start va retenir l&#8217;envoi de données, et ob_end_flush les liberera <img
src='http://blog.darklg.fr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br
/> Cette &laquo;&nbsp;bidouille&nbsp;&raquo; permet d&#8217;envoyer des cookies en plein milieu d&#8217;une page, et d&#8217;autres choses pas très nettes <img
src='http://blog.darklg.fr/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> .</li></ul><p>J&#8217;espère que cet article a pu vous aider à résoudre l&#8217;erreur &laquo;&nbsp;<strong>Cannot modify header information</strong>&laquo;&nbsp;.Sinon, je peux toujours vous donner un coup de main dans <a
href="http://blog.darklg.fr/136/php-erreur-cannot-modify-header-information/#comments">les commentaires</a> <img
src='http://blog.darklg.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p>Edit : une autre solution proposée par le blog <a
href="http://midnight-cafe.co.uk/cpanel-apache/warning-cannot-modify-header-information/">Midnight Cafe</a><br
/> Ajoutez cette ligne dans votre fichier .htaccess :<br
/> <code>output_buffering on</code></p><p>Edit2 : Dans les commentaires, <strong>Gloup</strong> évoque le fait que des fichiers en <strong>UTF-8 avec BOM</strong> peuvent provoquer cette erreur. Il suffit alors de les réencoder en <strong>UTF-8 sans BOM</strong> !</p><hr
/><p
style="font-size : 10px;"> Un article publi&eacute; sur <a
href="http://blog.darklg.fr">Darklg Blog</a> &copy; 2010<br
/> Lien vers l'article original : <a
href="http://blog.darklg.fr/136/php-erreur-cannot-modify-header-information/">[PHP] Erreur : Cannot modify header information : headers already sent by</a><br
/> <a
rel="external nofollow" href="http://minurl.fr/?twitter&amp;titrelien=Darklg+Blog+%3A+%5BPHP%5D+Erreur+%3A+Cannot+modify+header+information+%3A+headers+already+sent+by&amp;url=http://blog.darklg.fr/136/php-erreur-cannot-modify-header-information/" title="Envoyer vers Twitter, avec MinURL !">Partager cet article sur Twitter</a></p>]]></content:encoded> <wfw:commentRss>http://blog.darklg.fr/136/php-erreur-cannot-modify-header-information/feed/</wfw:commentRss> <slash:comments>11</slash:comments> </item> <item><title>[PHP] Comment désactiver l&#039;entête x-powered-by</title><link>http://blog.darklg.fr/143/php-desactiver-entete-x-powered-by/</link> <comments>http://blog.darklg.fr/143/php-desactiver-entete-x-powered-by/#comments</comments> <pubDate>Wed, 22 Oct 2008 16:01:59 +0000</pubDate> <dc:creator>darklg</dc:creator> <category><![CDATA[Développement PHP / MySQL]]></category> <category><![CDATA[astuce]]></category> <category><![CDATA[php]]></category><guid
isPermaLink="false">http://blog.darklg.fr/?p=143</guid> <description><![CDATA[L&#8217;entête HTTP x-powered-by permet d&#8217;afficher dans l&#8217;entête d&#8217;une page générée par PHP, la version de PHP utilisée. Utile aux développeurs, son usage est déconseillé en production, car il informe sur les failles de votre serveur, peut causer des erreurs de type &#160;&#187; Cannot Modify Header Information &#171;&#160;, et provoquer d&#8217;atroces souffrances. Bon ok, le dernier ... <a
href="http://blog.darklg.fr/143/php-desactiver-entete-x-powered-by/">lire la suite</a>]]></description> <content:encoded><![CDATA[<p>L&#8217;entête HTTP <strong>x-powered-by</strong> permet d&#8217;afficher dans l&#8217;entête d&#8217;une page générée par PHP, la version de PHP utilisée.<br
/> Utile aux développeurs, son usage est déconseillé en production, car il informe sur les failles de votre serveur, peut causer des erreurs de type &nbsp;&raquo; <strong>Cannot Modify Header Information</strong> &laquo;&nbsp;, et provoquer d&#8217;atroces souffrances. Bon ok, le dernier point est assez subjectif.</p><p>Pour désactiver <strong>x-powered-by</strong>, il vous suffit de créer &#8211; ou de modifier &#8211; un fichier php.ini dans le dossier où s&#8217;execute votre script et d&#8217;ajouter la ligne :<br
/> <code>expose_php = off</code></p><p>Si vous pouvez modifier votre fichier php.ini principal, c&#8217;est encore mieux !</p><hr
/><p
style="font-size : 10px;"> Un article publi&eacute; sur <a
href="http://blog.darklg.fr">Darklg Blog</a> &copy; 2010<br
/> Lien vers l'article original : <a
href="http://blog.darklg.fr/143/php-desactiver-entete-x-powered-by/">[PHP] Comment désactiver l&#039;entête x-powered-by</a><br
/> <a
rel="external nofollow" href="http://minurl.fr/?twitter&amp;titrelien=Darklg+Blog+%3A+%5BPHP%5D+Comment+d%C3%A9sactiver+l%26%23039%3Bent%C3%AAte+x-powered-by&amp;url=http://blog.darklg.fr/143/php-desactiver-entete-x-powered-by/" title="Envoyer vers Twitter, avec MinURL !">Partager cet article sur Twitter</a></p>]]></content:encoded> <wfw:commentRss>http://blog.darklg.fr/143/php-desactiver-entete-x-powered-by/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Nettoyer une chaine pour une URL, en PHP</title><link>http://blog.darklg.fr/94/nettoyer-une-chaine-pour-une-url-en-php/</link> <comments>http://blog.darklg.fr/94/nettoyer-une-chaine-pour-une-url-en-php/#comments</comments> <pubDate>Tue, 22 Jul 2008 15:58:05 +0000</pubDate> <dc:creator>darklg</dc:creator> <category><![CDATA[Développement PHP / MySQL]]></category> <category><![CDATA[Référencement]]></category> <category><![CDATA[php]]></category> <category><![CDATA[url]]></category><guid
isPermaLink="false">http://blog.darklg.fr/?p=94</guid> <description><![CDATA[Un problème simple peut parfois se poser à vous : Vous disposez d&#8217;une chaîne de caractères ( un titre d&#8217;article, par exemple ), que vous souhaitez utiliser pour une URL. Malheureusement, vous ne pouvez pas utiliser directement cette chaine de caractères, qui ne serait pas optimisée pour le référencement, et très peu lisible. C&#8217;est là ... <a
href="http://blog.darklg.fr/94/nettoyer-une-chaine-pour-une-url-en-php/">lire la suite</a>]]></description> <content:encoded><![CDATA[<p>Un problème simple peut parfois se poser à vous :<br
/> Vous disposez d&#8217;une chaîne de caractères ( un titre d&#8217;article, par exemple ), que vous souhaitez utiliser pour une URL. <strong>Malheureusement</strong>, vous ne pouvez pas utiliser directement cette chaine de caractères, qui ne serait pas optimisée pour le référencement, et très peu lisible.</p><p>C&#8217;est là qu&#8217;intervient la fonction <strong>clear_url()</strong>. Cette dernière nettoie votre chaine, et en retourne une propre et optimisée, pour une url, un identifiant, etc <img
src='http://blog.darklg.fr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> clean_url<span style="color: #009900;">&#40;</span><span style="color: #000088;">$texte</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//Suppression des espaces en début et fin de chaîne</span>
	<span style="color: #000088;">$texte</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$texte</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Suppression des accents</span>
	<span style="color: #000088;">$texte</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$texte</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËéèêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//mise en minuscule</span>
	<span style="color: #000088;">$texte</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$texte</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Suppression des espaces et caracteres spéciaux</span>
	<span style="color: #000088;">$texte</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">,</span><span style="color: #000088;">$texte</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$texte</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#([^a-z0-9-])#'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">,</span><span style="color: #000088;">$texte</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Suppression des tirets multiples</span>
	<span style="color: #000088;">$texte</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#([-]+)#'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">,</span><span style="color: #000088;">$texte</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Suppression du premier caractère si c'est un tiret</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$texte</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'-'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$texte</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$texte</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Suppression du dernier caractère si c'est un tiret</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$texte</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'-'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$texte</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$texte</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$texte</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p>Elle peut être optimisée ( en virant les étapes intermédiaires ), mais est fonctionnelle et plutôt utile <img
src='http://blog.darklg.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br
/> Si vous avez une optimisation à partager, <strong>n&#8217;hésitez pas</strong> <img
src='http://blog.darklg.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><hr
/><p
style="font-size : 10px;"> Un article publi&eacute; sur <a
href="http://blog.darklg.fr">Darklg Blog</a> &copy; 2010<br
/> Lien vers l'article original : <a
href="http://blog.darklg.fr/94/nettoyer-une-chaine-pour-une-url-en-php/">Nettoyer une chaine pour une URL, en PHP</a><br
/> <a
rel="external nofollow" href="http://minurl.fr/?twitter&amp;titrelien=Darklg+Blog+%3A+Nettoyer+une+chaine+pour+une+URL%2C+en+PHP&amp;url=http://blog.darklg.fr/94/nettoyer-une-chaine-pour-une-url-en-php/" title="Envoyer vers Twitter, avec MinURL !">Partager cet article sur Twitter</a></p>]]></content:encoded> <wfw:commentRss>http://blog.darklg.fr/94/nettoyer-une-chaine-pour-une-url-en-php/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Trouver l&#039;âge exact en fonction d&#039;une date de naissance.</title><link>http://blog.darklg.fr/85/trouver-l-age-exact-en-fonction-d-une-date-de-naissance/</link> <comments>http://blog.darklg.fr/85/trouver-l-age-exact-en-fonction-d-une-date-de-naissance/#comments</comments> <pubDate>Sat, 19 Jul 2008 11:21:35 +0000</pubDate> <dc:creator>darklg</dc:creator> <category><![CDATA[Développement PHP / MySQL]]></category> <category><![CDATA[Référencement]]></category> <category><![CDATA[age]]></category> <category><![CDATA[anniversaire]]></category> <category><![CDATA[calcul]]></category> <category><![CDATA[php]]></category><guid
isPermaLink="false">http://blog.darklg.fr/?p=85</guid> <description><![CDATA[J&#8217;ai créé récemment une fonction simple et efficace pour récupérer l&#8217;âge d&#8217;un membre à partir de cette date de naissance. Trop souvent, j&#8217;ai vu des scripts donnant un âge approximatif calculé à partir des années de naissance. Donc voici ma création, qui récupère l&#8217;année de naissance, ainsi que le mois et le jour ( aux ... <a
href="http://blog.darklg.fr/85/trouver-l-age-exact-en-fonction-d-une-date-de-naissance/">lire la suite</a>]]></description> <content:encoded><![CDATA[<p>J&#8217;ai créé récemment une fonction simple et efficace pour récupérer l&#8217;âge d&#8217;un membre à partir de cette date de naissance. Trop souvent, j&#8217;ai vu des scripts donnant un âge approximatif calculé à partir des années de naissance.<br
/> Donc voici ma création, qui récupère <strong>l&#8217;année de naissance</strong>, ainsi que le <strong>mois</strong> et le <strong>jour</strong> ( aux formats date <strong>&#8216;Y&#8217;</strong>, <strong>&#8216;n&#8217;</strong> et <strong>&#8216;j&#8217;</strong>, donc 1999, 2000 &#8230; ; 1, 2, 3, &#8230;, 11, 12 et 1, 2, 3, &#8230;, 30, 31 )</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> age<span style="color: #009900;">&#40;</span><span style="color: #000088;">$annee_naissance</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mois_naissance</span><span style="color: #339933;">,</span> <span style="color: #000088;">$jour_naissance</span><span style="color: #339933;">,</span> <span style="color: #000088;">$timestamp</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Si on veut vérifier à la date actuelle ( par défaut )</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$timestamp</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$timestamp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//On evalue l'age, à un an par exces</span>
	<span style="color: #000088;">$age</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y'</span><span style="color: #339933;">,</span><span style="color: #000088;">$timestamp</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$annee_naissance</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//On retire un an si l'anniversaire n'est pas encore passé</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mois_naissance</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'n'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$timestamp</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$mois_naissance</span><span style="color: #339933;">==</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'n'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$timestamp</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$jour_naissance</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'j'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$timestamp</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$age</span><span style="color: #339933;">--;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$age</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> age<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1987'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'9'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'11'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Affichera 20</span>
<span style="color: #b1b100;">echo</span> age<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1987</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">9</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">11</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Affichera 20</span>
<span style="color: #b1b100;">echo</span> age<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1987'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'09'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'11'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Affichera 20</span>
<span style="color: #b1b100;">echo</span> age<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1987</span><span style="color: #339933;">,</span><span style="color:#800080;">09</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">11</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Ne fonctionnera pas : mauvais format de date !</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div><p>à noter un paramètre optionnel : $timestamp, si vous souhaitez calculer un age à une date en particulier <img
src='http://blog.darklg.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br
/> Si cette fonction vous est utile, c&#8217;est impeccable !<br
/> ( Et si vous trouvez un bug quelconque, n&#8217;hésitez pas à me le signaler, merci <img
src='http://blog.darklg.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> )</p><hr
/><p
style="font-size : 10px;"> Un article publi&eacute; sur <a
href="http://blog.darklg.fr">Darklg Blog</a> &copy; 2010<br
/> Lien vers l'article original : <a
href="http://blog.darklg.fr/85/trouver-l-age-exact-en-fonction-d-une-date-de-naissance/">Trouver l&#039;âge exact en fonction d&#039;une date de naissance.</a><br
/> <a
rel="external nofollow" href="http://minurl.fr/?twitter&amp;titrelien=Darklg+Blog+%3A+Trouver+l%26%23039%3B%C3%A2ge+exact+en+fonction+d%26%23039%3Bune+date+de+naissance.&amp;url=http://blog.darklg.fr/85/trouver-l-age-exact-en-fonction-d-une-date-de-naissance/" title="Envoyer vers Twitter, avec MinURL !">Partager cet article sur Twitter</a></p>]]></content:encoded> <wfw:commentRss>http://blog.darklg.fr/85/trouver-l-age-exact-en-fonction-d-une-date-de-naissance/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)

Served from: blog.darklg.fr @ 2010-09-10 11:39:12 -->