<?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>Naeh.net &#187; PHP / MySQL</title>
	<atom:link href="http://naeh.net/categorie/programmation/php-mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://naeh.net</link>
	<description>Le mémo du développeur</description>
	<lastBuildDate>Sun, 07 Aug 2011 20:29:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>upload avec barre de progression</title>
		<link>http://naeh.net/upload-avec-barre-de-progression/</link>
		<comments>http://naeh.net/upload-avec-barre-de-progression/#comments</comments>
		<pubDate>Sun, 07 Aug 2011 20:29:39 +0000</pubDate>
		<dc:creator>Naeh</dc:creator>
				<category><![CDATA[Linux - Logiciels]]></category>
		<category><![CDATA[PHP / MySQL]]></category>
		<category><![CDATA[Programmation]]></category>

		<guid isPermaLink="false">http://naeh.net/?p=213</guid>
		<description><![CDATA[dans cet article-tuto nous allons voir comment mettre en place un système d'upload avec une sympathique barre de progression. les pré-requis : - un serveur web Apache - PHP5 avec l'extension APC - jquery dans ce tuto je pars du principe qu'Apache et PHP sont installés et fonctionnels, on va juste voir comment installer APC [...]]]></description>
			<content:encoded><![CDATA[<p>dans cet article-tuto nous allons voir comment mettre en place un système d'upload avec une sympathique barre de progression.</p>
<p>les pré-requis :<br />
- un serveur web Apache<br />
- PHP5 avec l'extension APC<br />
- <a href="http://jquery.com/" target="_blank">jquery</a></p>
<p>dans ce tuto je pars du principe qu'Apache et PHP sont installés et fonctionnels, on va juste voir comment installer APC et activer le suivi de la progression d'upload :</p>

<div class="wp_codebox"><table><tr id="p2138"><td class="code" id="p213code8"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php-apc
<span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>php5<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>conf.d<span style="color: #000000; font-weight: bold;">/</span>apc.ini</pre></td></tr></table></div>

<p>ajouter à la fin du fichier :</p>

<div class="wp_codebox"><table><tr id="p2139"><td class="code" id="p213code9"><pre class="text" style="font-family:monospace;">apc.rfc1867 = on</pre></td></tr></table></div>

<p>cette ligne magique, activera la suivi de progression d'upload sur le serveur.</p>
<p>on reload apache :</p>

<div class="wp_codebox"><table><tr id="p21310"><td class="code" id="p213code10"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache2 reload</pre></td></tr></table></div>

<p>le coté système de la chose est maintenant terminé, passons à l'upload :</p>
<p>pour la petite histoire, voici ce que l'on va faire :<br />
on va créer un formulaire, qui sera validé vers (target) une iframe invisible, le temps que l'upload se passe, on va contacter un petit script php en ajax (très souvent) qui va nous dire où en est l'upload, en nous retournant le pourcentage d'avancement (tout simplement), avec cette valeur, on va pouvoir mettre en place une barre de progression très facilement.</p>
<p>pour commencer, le formulaire :</p>

<div class="wp_codebox"><table><tr id="p21311"><td class="code" id="p213code11"><pre class="html" style="font-family:monospace;">&lt;?php $unique_id = uniqid(); //id unique de notre formulaire ?&gt;
&nbsp;
&lt;!-- iframe caché en javascript dans laquelle se fait l'upload, elle affichera le message de confirmation / ou erreur à la fin de l'upload --&gt;
&lt;iframe frameborder=&quot;0&quot; border=&quot;0&quot; id=&quot;upload_to&quot; name=&quot;upload_to&quot; style=&quot;width: 100%; border:none; border-color: #fff;&quot; scrolling=&quot;no&quot;&gt;&lt;/iframe&gt;
&nbsp;
&lt;!-- le formulaire d'upload --&gt;
&lt;form id=&quot;upload_form&quot; enctype=&quot;multipart/form-data&quot; action=&quot;upload.php&quot; method=&quot;post&quot; target=&quot;upload_to&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;APC_UPLOAD_PROGRESS&quot; id=&quot;progress_key&quot; value=&quot;&lt;?php echo $unique_id?&gt;&quot;/&gt;
&lt;div id=&quot;progressouter&quot;&gt;
	&lt;div id=&quot;progressinner&quot;&gt;&lt;span id=&quot;progression_percent&quot;&gt;0&amp;nbsp;%&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;input id=&quot;file&quot; type=&quot;file&quot; name=&quot;file&quot; size=&quot;30&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot;valider&quot; /&gt;&lt;/p&gt;
&lt;/form&gt;</pre></td></tr></table></div>

<p>le bout de php au début, permet de donner un id unique au formulaire<br />
il est renseigné dans le champ "<strong>APC_UPLOAD_PROGRESS</strong>" ceci permet au système de donner un id à l'upload en cours, ce qui nous permettra de consulter la progression en le connaissant (l'id).</p>
<p>l'iframe n'a rien de spéciale, elle est caché en javascript (voir plus bas).</p>
<p>le formulaire contient l'HTML de la barre de progression (la div <strong>progressouter</strong>, on pourrait la mettre ailleurs, chacun fait ce qu'il veut. et le champ hidden <strong>APC_UPLOAD_PROGRESS</strong> comme dit plus haut, obligatoire pour le suivi de l'upload.</p>
<p>passons maintenant à notre script d'upload : <strong>upload.php</strong><br />
l'upload en lui même n'est pas vraiment notre sujet du jour, donc, je prends l'exemple d'upload le plus simple au monde (donné sur <a href="http://php.net" target="_blank">php.net</a>)</p>

<div class="wp_codebox"><table><tr id="p21312"><td class="code" id="p213code12"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$uploaddir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/var/www/uploads/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$uploadfile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$uploaddir</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/basename"><span style="color: #990000;">basename</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/move_uploaded_file"><span style="color: #990000;">move_uploaded_file</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$uploadfile</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;File is valid, and was successfully uploaded.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Possible file upload attack!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>on aura besoin du fameux script qui retourne le pourcentage d'avancement de l'upload : <strong>progress.php</strong></p>

<div class="wp_codebox"><table><tr id="p21313"><td class="code" id="p213code13"><pre class="php" style="font-family:monospace;"><a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cache-Control: no-cache&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//utile pour IE (problème avec l'ajax)</span>
<span style="color: #666666; font-style: italic;">//progression</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'progress_key'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$upload</span> <span style="color: #339933;">=</span> apc_fetch<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'upload_'</span><span style="color: #339933;">.</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'progress_key'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$percent</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1000</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$upload</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;">$upload</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'done'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$percent</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$upload</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'total'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$percent</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">else</span>
            <span style="color: #000088;">$percent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$upload</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'current'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$upload</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'total'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">echo</span> <a href="http://www.php.net/number_format"><span style="color: #990000;">number_format</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$percent</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>c'est presque fini, il ne reste plus que le javascript :</p>

<div class="wp_codebox"><table><tr id="p21314"><td class="code" id="p213code14"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> getProgress<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> count <span style="color: #339933;">=</span> Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">/// Math.random sélectionne un nombre entre 0 et 1 ( ex: 0.6489534931546957) pour IE aussi (même si le header no-cache devrait suffire)</span>
    $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span>
        url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;/progress.php?progress_key=&lt;?php echo($unique_id)?&gt;&amp;count=&quot;</span><span style="color: #339933;">+</span>count<span style="color: #339933;">,</span>
        success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>percent<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>percent <span style="color: #339933;">&lt;=</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#progressinner&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;width&quot;</span><span style="color: #339933;">,</span> percent<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;%&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#progression_percent&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span>percent<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot; %&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>percent <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;getProgress()&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>percent <span style="color: #339933;">==</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#upload_to&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#file&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> startProgress<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#progressouter, #progression_percent&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;getProgress()&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#upload_to&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#upload_form'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        startProgress<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>en gros (très gros même) ce js va cacher l'iframe au chargement de la page, et à la validation du formulaire, il va lancer la fonction startProgress(), qui elle, va afficher la barre de progression et lancer régulièrement getProgress, qui elle, fait un appel ajax à notre script progress.php et lui indiquant l'unique id généré tout au début de la page et en fonction du retour, elle va ajuster la largeur de la barre de progression.</p>
<p>si vous avez des questions, n'hésitez pas à les poser dans les commentaires.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fnaeh.net%2Fupload-avec-barre-de-progression%2F&amp;title=upload%20avec%20barre%20de%20progression" id="wpa2a_2"><img src="http://naeh.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://naeh.net/upload-avec-barre-de-progression/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>convertir un array en utf8</title>
		<link>http://naeh.net/convertir-un-array-en-utf8/</link>
		<comments>http://naeh.net/convertir-un-array-en-utf8/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 20:03:22 +0000</pubDate>
		<dc:creator>Naeh</dc:creator>
				<category><![CDATA[PHP / MySQL]]></category>
		<category><![CDATA[Programmation]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[utf-8]]></category>

		<guid isPermaLink="false">http://naeh.net/?p=100</guid>
		<description><![CDATA[dans un précédent article nous avons vu comment convertir un texte en utf8. aujourd'hui on va voir comment faire la même chose mais avec un tableau, sans passer par un foreach, ni aucune autre boucle. pour cela nous allons utiliser une seule fonction qui convertira ce qu'on lui donne en entrée en utf8. pour l'instant [...]]]></description>
			<content:encoded><![CDATA[<p>dans un <a href="http://naeh.net/comment-convertir-un-texte-en-utf-8/">précédent article</a> nous avons vu comment convertir un texte en utf8.</p>
<p>aujourd'hui on va voir comment faire la même chose mais avec un tableau, sans passer par un foreach, ni aucune autre boucle.</p>
<p>pour cela nous allons utiliser une seule fonction qui convertira ce qu'on lui donne en entrée en utf8.<br />
pour l'instant elle va savoir gérer, les chaînes de caractères et les tableaux.</p>

<div class="wp_codebox"><table><tr id="p10017"><td class="code" id="p100code17"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> toUTF8<span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</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><a href="http://www.php.net/is_array"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <a href="http://www.php.net/array_walk_recursive"><span style="color: #990000;">array_walk_recursive</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #339933;">,</span> <a href="http://www.php.net/create_function"><span style="color: #990000;">create_function</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;$item, $index'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'$item = toUTF8($item);'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$param</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <a href="http://www.php.net/mb_detect_order"><span style="color: #990000;">mb_detect_order</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'UTF-8, ISO-8859-15, ISO-8859-1, Windows-1252'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">//parfois si le dernier caractère de la chaine est accentué, la conversion peut foirer,</span>
    <span style="color: #666666; font-style: italic;">//donc on force avec un caractère qui ne l'est pas.</span>
    <span style="color: #666666; font-style: italic;">//(astuce trouvée sur les commentaires de la doc sur php.net)</span>
    <span style="color: #000088;">$param</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'_'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$currentCharset</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mb_detect_encoding"><span style="color: #990000;">mb_detect_encoding</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$currentCharset</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'UTF-8'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$param</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mb_convert_encoding"><span style="color: #990000;">mb_convert_encoding</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'UTF-8'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currentCharset</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <a href="http://www.php.net/strlen"><span style="color: #990000;">strlen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</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: #009900;">&#125;</span></pre></td></tr></table></div>

<p>et voilà, cette fonction convertira array ou string en utf8 sans brancher...</p>
<p>en bonus voici une fonction somme que j'ai trouvé dans les commentaire de la doc sur php.net (une sorte de coup de coeur pour moi <img src='http://naeh.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> )</p>

<div class="wp_codebox"><table><tr id="p10018"><td class="code" id="p100code18"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> sum<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$s</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/func_get_args"><span style="color: #990000;">func_get_args</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$s</span><span style="color: #339933;">+=</span> <a href="http://www.php.net/is_numeric"><span style="color: #990000;">is_numeric</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span>?<span style="color: #000088;">$a</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$s</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">print</span> sum<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// will return 21</span>
<span style="color: #b1b100;">print</span> sum<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</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: #666666; font-style: italic;">// will return 6</span>
<span style="color: #b1b100;">print</span> sum<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// will return 10</span></pre></td></tr></table></div>

<p>trop fort non ?</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fnaeh.net%2Fconvertir-un-array-en-utf8%2F&amp;title=convertir%20un%20array%20en%20utf8" id="wpa2a_4"><img src="http://naeh.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://naeh.net/convertir-un-array-en-utf8/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Installer libssh2, ssh2 pour php</title>
		<link>http://naeh.net/installer-libssh2-ssh2-pour-php/</link>
		<comments>http://naeh.net/installer-libssh2-ssh2-pour-php/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 20:51:00 +0000</pubDate>
		<dc:creator>Naeh</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Linux - Logiciels]]></category>
		<category><![CDATA[PHP / MySQL]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[libssh2]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[Serveur]]></category>
		<category><![CDATA[ssh2]]></category>

		<guid isPermaLink="false">http://naeh.net/?p=56</guid>
		<description><![CDATA[Dans cet article nous allons voir comment installer l'extension ssh2 pour php5, cette extension permet l'utilisation de fonctionnalités SSH2 avec php (très utiles quand on veut faire du SFTP par exemple) pour plus d'informations cf. la documentation officielle sur php.net Pour l'installation, ce n'est pas très compliqué, il suffit de suivre ces quelques étapes à [...]]]></description>
			<content:encoded><![CDATA[<p>Dans cet article nous allons voir comment installer l'extension ssh2 pour php5, cette extension permet l'utilisation de fonctionnalités SSH2 avec php (très utiles quand on veut faire du SFTP par exemple) pour plus d'informations cf. <a href="http://fr.php.net/manual/fr/book.ssh2.php" target="_blank">la documentation officielle sur php.net</a></p>
<p>Pour l'installation, ce n'est pas très compliqué, il suffit de suivre ces quelques étapes à la lettre et tout ira très bien <img src='http://naeh.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>tout d'abord il faut s'assurer d'avoir les bons paquets d'installés, en voici une liste :</p>
<ul>
<li>php5-dev</li>
<li>openssl</li>
<li>libssl-dev</li>
<li>gcc</li>
<li>make</li>
<li>etc. je suppose que si vous installez cette extension, c'est que vous avez déjà php, apache etc.</li>
</ul>
<p><em>Toute la suite s'effectue en root</em></p>
<p>mais avant toute chose, n'oublions pas de faire un petit :</p>

<div class="wp_codebox"><table><tr id="p5629"><td class="code" id="p56code29"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> update
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> upgrade</pre></td></tr></table></div>

<p>en suite il faut créer un répertoire de travail :</p>

<div class="wp_codebox"><table><tr id="p5630"><td class="code" id="p56code30"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> libssh2
<span style="color: #7a0874; font-weight: bold;">cd</span> libssh2</pre></td></tr></table></div>

<p>ensuite télécharger libssh2 :</p>

<div class="wp_codebox"><table><tr id="p5631"><td class="code" id="p56code31"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>ovh.dl.sourceforge.net<span style="color: #000000; font-weight: bold;">/</span>sourceforge<span style="color: #000000; font-weight: bold;">/</span>libssh2<span style="color: #000000; font-weight: bold;">/</span>libssh2-<span style="color: #000000;">0.14</span>.tar.gz</pre></td></tr></table></div>

<p>puis l'extraire :</p>

<div class="wp_codebox"><table><tr id="p5632"><td class="code" id="p56code32"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xzvf</span> libssh2-<span style="color: #000000;">0.14</span>.tar.gz</pre></td></tr></table></div>

<p>aller dans le répertoire créé et installer libssh2 :</p>

<div class="wp_codebox"><table><tr id="p5633"><td class="code" id="p56code33"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> libssh2-<span style="color: #000000;">0.14</span>
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">make</span> all <span style="color: #c20cb9; font-weight: bold;">install</span></pre></td></tr></table></div>

<p>maintenant que libssh2 est installée, passons a ssh2 :</p>
<p>on sort du repertoire de libssh2 et on télécharge ssh2 :</p>

<div class="wp_codebox"><table><tr id="p5634"><td class="code" id="p56code34"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ..
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>pecl.php.net<span style="color: #000000; font-weight: bold;">/</span>get<span style="color: #000000; font-weight: bold;">/</span>ssh2-<span style="color: #000000;">0.10</span>.tgz</pre></td></tr></table></div>

<p>extraire l'archive téléchargée :</p>

<div class="wp_codebox"><table><tr id="p5635"><td class="code" id="p56code35"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xzvf</span> ssh2-<span style="color: #000000;">0.10</span>.tgz</pre></td></tr></table></div>

<p>aller dans le répertoire créé et installer ssh2 :</p>

<div class="wp_codebox"><table><tr id="p5636"><td class="code" id="p56code36"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ssh2-<span style="color: #000000;">0.10</span>
phpize <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> .<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-ssh2</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">make</span></pre></td></tr></table></div>

<p>maintenant que l'installation est terminée, on active l'extension, ici on va copier le fichier ssh2.so dans le répertoire des extension de php5 (il peut être différent du mien selon la distrib et l'installation) :</p>

<div class="wp_codebox"><table><tr id="p5637"><td class="code" id="p56code37"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> modules<span style="color: #000000; font-weight: bold;">/</span>ssh2.so <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>php5<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">20060613</span>+lfs</pre></td></tr></table></div>

<p>puis on ajoute l'extension en créant un fichier ssh2.ini dans le répertoire conf.d (comme pour toutes les autres extensions de php) on n'oublie pas de le faire pour apache mais aussi pour le mode CLI.</p>

<div class="wp_codebox"><table><tr id="p5638"><td class="code" id="p56code38"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;extension=ssh2.so&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>php5<span style="color: #000000; font-weight: bold;">/</span>cli<span style="color: #000000; font-weight: bold;">/</span>conf.d<span style="color: #000000; font-weight: bold;">/</span>ssh2.ini
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;extension=ssh2.so&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>php5<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>conf.d<span style="color: #000000; font-weight: bold;">/</span>ssh2.ini
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache2 restart</pre></td></tr></table></div>

<p>Et voilà, notre extension est installée, a vous ssh2 et sftp avec php <img src='http://naeh.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fnaeh.net%2Finstaller-libssh2-ssh2-pour-php%2F&amp;title=Installer%20libssh2%2C%20ssh2%20pour%20php" id="wpa2a_6"><img src="http://naeh.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://naeh.net/installer-libssh2-ssh2-pour-php/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Comment installer fileinfo sous debian</title>
		<link>http://naeh.net/installation-fileinfo/</link>
		<comments>http://naeh.net/installation-fileinfo/#comments</comments>
		<pubDate>Wed, 14 May 2008 15:43:14 +0000</pubDate>
		<dc:creator>Naeh</dc:creator>
				<category><![CDATA[Linux - Logiciels]]></category>
		<category><![CDATA[PHP / MySQL]]></category>
		<category><![CDATA[Programmation]]></category>
		<category><![CDATA[apt-get]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[fileinfo]]></category>
		<category><![CDATA[libmagic]]></category>
		<category><![CDATA[pear]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[phpize]]></category>

		<guid isPermaLink="false">http://naeh.net/installation-fileinfo/</guid>
		<description><![CDATA[Les fonctions de l'extension FileInfo essaient de savoir le type de contenu et l’encodage d’un fichier en regardant certaines séquences d’octet "magique" à des positions spécifiques à l’intérieur du fichier. Bien qu'il ne s'agit pas d'une approche infaillible, la méthode heuristique effectue un très bon travail. le problème avec cette extension c'est qu'elle est un [...]]]></description>
			<content:encoded><![CDATA[<p>Les fonctions de l'extension <a href="http://fr3.php.net/manual/fr/book.fileinfo.php" target="_blank">FileInfo</a> essaient de savoir le type de contenu et l’encodage d’un fichier en regardant certaines séquences d’octet "magique" à des positions spécifiques à l’intérieur du fichier. Bien qu'il ne s'agit pas d'une approche infaillible, la méthode heuristique effectue un très bon travail.</p>
<p>le problème avec cette extension c'est qu'elle est un peu dur à installer, en réalité pas si dur que ça, il suffit de prendre le temps de le faire. Il faut juste savoir qu'un simple <strong>apt-get install php5-fileinfo</strong> ne suffira pas, tout simplement parce qu'il n'existe pas de paquet debian pour cette extension (pas encore...).</p>
<p>Donc pour l'installer, voici la procédure :<br />
Il faut d'abord installer <a href="http://pear.php.net/manual/fr/introduction.php" target="_blank">PEAR</a> :</p>

<div class="wp_codebox"><table><tr id="p5245"><td class="code" id="p52code45"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php-pear</pre></td></tr></table></div>

<p>ensuite il faut installer php5-dev si ce n'est pas déjà fait, ceci installera phpize ce qui nous évitera l'erreur :</p>

<div class="wp_codebox"><table><tr id="p5246"><td class="code" id="p52code46"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sh</span>: phpize: <span style="color: #7a0874; font-weight: bold;">command</span> not found
ERROR: <span style="color: #000000; font-weight: bold;">`</span>phpize<span style="color: #ff0000;">' failed</span></pre></td></tr></table></div>

<p>installation de php5-dev :</p>

<div class="wp_codebox"><table><tr id="p5247"><td class="code" id="p52code47"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-dev</pre></td></tr></table></div>

<p>c'est presque bon mais pas encore :<br />
maintenant il faut installer libmagic pour nous éviter une erreur lors de l'installation de fileinfo :</p>

<div class="wp_codebox"><table><tr id="p5248"><td class="code" id="p52code48"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libmagic-dev</pre></td></tr></table></div>

<p>maintenant tout est bon, nous allons enfin pouvoir lancer l'installation de notre extension :</p>

<div class="wp_codebox"><table><tr id="p5249"><td class="code" id="p52code49"><pre class="bash" style="font-family:monospace;">pecl <span style="color: #c20cb9; font-weight: bold;">install</span> fileinfo</pre></td></tr></table></div>

<p>Voilà, maintenant fileinfo est installée, nous allons pouvoir vérifier les types mime des fichiers avec des méthodes plus fiables <img src='http://naeh.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Normalement tout devrait fonctionner maintenant, mais il ce peut que l'extension ne soit pas activée comme il faut, dans ce cas il faudra créer un fichier <strong>fileinfo.ini</strong> dans <strong>/etc/php5/apache2/conf.d</strong> avec le contenu suivant :</p>

<div class="wp_codebox"><table><tr id="p5250"><td class="code" id="p52code50"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">extension</span>=fileinfo.so</pre></td></tr></table></div>

<p>reloader apache avec /etc/init.d/apache2 reload et le tour est joué <img src='http://naeh.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fnaeh.net%2Finstallation-fileinfo%2F&amp;title=Comment%20installer%20fileinfo%20sous%20debian" id="wpa2a_8"><img src="http://naeh.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://naeh.net/installation-fileinfo/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Forcer le téléchargement d&#039;un fichier avec PHP</title>
		<link>http://naeh.net/forcer-le-telechargement-dun-fichier-avec-php/</link>
		<comments>http://naeh.net/forcer-le-telechargement-dun-fichier-avec-php/#comments</comments>
		<pubDate>Tue, 18 Mar 2008 22:16:33 +0000</pubDate>
		<dc:creator>Naeh</dc:creator>
				<category><![CDATA[PHP / MySQL]]></category>
		<category><![CDATA[Programmation]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Serveur]]></category>
		<category><![CDATA[telecharger]]></category>

		<guid isPermaLink="false">http://naeh.net/forcer-le-telechargement-dun-fichier-avec-php/</guid>
		<description><![CDATA[Dance cet article nous allons voir comment forcer le navigateur à télécharger un fichier (n'importe lequel) au lieux de l'ouvrir. Pour cela nous allons utiliser les Headers qu'envoie le serveur au navigateur (fonction header de php). Voici le code a utiliser : //date actuelle $date = gmdate&#40;'D, d M Y H:i:s'&#41;; &#160; header&#40;&#34;Content-Type: text/xml&#34;&#41;; //Ici [...]]]></description>
			<content:encoded><![CDATA[<p>Dance cet article nous allons voir comment forcer le navigateur à télécharger un fichier (n'importe lequel) au lieux de l'ouvrir. Pour cela nous allons utiliser les <strong>Headers</strong> qu'envoie le serveur au navigateur (<a href="http://fr3.php.net/manual/fr/function.header.php" target="_blank">fonction header de php</a>).</p>
<p>Voici le code a utiliser :</p>

<div class="wp_codebox"><table><tr id="p5153"><td class="code" id="p51code53"><pre class="php" style="font-family:monospace;"> <span style="color: #666666; font-style: italic;">//date actuelle</span>
<span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/gmdate"><span style="color: #990000;">gmdate</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'D, d M Y H:i:s'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: text/xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Ici par exemple c'est pour un fichier XML, a changer en fonction du type mime du fichier voulu.</span>
<a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Disposition: attachment; filename=NOM_FICHIER.xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Last-Modified: '</span><span style="color: #339933;">.</span> <span style="color: #000088;">$date</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' GMT'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Expires: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//header specifique IE :s parce que sinon il aime pas</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #990000;">preg_match</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/msie|(microsoft internet explorer)/i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Cache-Control: must-revalidate, post-check=0, pre-check=0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Pragma: public'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
  <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Pragma: no-cache'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$CONTENU_DE_NOTRE_FICHIER</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// ou readfile('CHEMIN_FICHIER'); En fonction du type de fichier.</span></pre></td></tr></table></div>

<p>Le type Mime doit être celui du fichier qu'on veut pouvoir télécharger (<a href="http://www.c-p-f.org/divers-Liste_des_types_MIME-a15.html" target="_blank">liste des types mime disponibles</a>). En voici quelques exemples :</p>

<div class="wp_codebox"><table><tr id="p5154"><td class="code" id="p51code54"><pre class="bash" style="font-family:monospace;">image GIF : image<span style="color: #000000; font-weight: bold;">/</span>gif
fichier XML : text<span style="color: #000000; font-weight: bold;">/</span>xml
fichier rtf : application<span style="color: #000000; font-weight: bold;">/</span>rtf
fichier avi : video<span style="color: #000000; font-weight: bold;">/</span>msvideo</pre></td></tr></table></div>

<p>Maintenant à vos fichiers dl.php <img src='http://naeh.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fnaeh.net%2Fforcer-le-telechargement-dun-fichier-avec-php%2F&amp;title=Forcer%20le%20t%C3%A9l%C3%A9chargement%20d%26%23039%3Bun%20fichier%20avec%20PHP" id="wpa2a_10"><img src="http://naeh.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://naeh.net/forcer-le-telechargement-dun-fichier-avec-php/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Extraire le contenu d&#039;un zip directement sur son FTP chez free</title>
		<link>http://naeh.net/extraire-le-contenu-dun-zip-directement-sur-son-ftp-chez-free/</link>
		<comments>http://naeh.net/extraire-le-contenu-dun-zip-directement-sur-son-ftp-chez-free/#comments</comments>
		<pubDate>Sun, 16 Mar 2008 17:13:21 +0000</pubDate>
		<dc:creator>Naeh</dc:creator>
				<category><![CDATA[PHP / MySQL]]></category>
		<category><![CDATA[Programmation]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[extraire]]></category>
		<category><![CDATA[hébergement]]></category>
		<category><![CDATA[librairie]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Serveur]]></category>
		<category><![CDATA[zip]]></category>

		<guid isPermaLink="false">http://naeh.net/extraire-le-contenu-dun-zip-directement-sur-son-ftp-chez-free/</guid>
		<description><![CDATA[Dans cette article nous allons voir comment procéder pour dézippé le contenu d'une archive directement sur son FTP free. Ceci peut être très intéressant si on a plusieurs (beaucoup) fichiers à envoyer sur le ftp, parfois ce genre d'upload peut s'avérer très difficile en fonction de la connexion, du logicile client FTP, mais aussi de [...]]]></description>
			<content:encoded><![CDATA[<p>Dans cette article nous allons voir comment procéder pour dézippé le contenu d'une archive directement sur son FTP free. Ceci peut être très intéressant si on a plusieurs (beaucoup) fichiers à envoyer sur le ftp, parfois ce genre d'upload peut s'avérer très difficile en fonction de la connexion, du logicile client FTP, mais aussi de l'humeur du serveur FTP de chez free. On peut se retrouver avec un certain nombre de fichiers qui ne seront pas envoyé (perdus en route ?!).</p>
<p>L'astuce consiste à mettre tous ses fichiers dans ZIP, uploader le zip sur le FTP et l'extraire sur place avec script PHP. Parce que envoyer UN SEUL fichier quelque soit sa taille, est toujours plus simple que d'en envoyer 36 000.</p>
<p>Pour commencer il faut savoir que Free ne propose aucune librairie PHP pour gérer les archives, donc nous utiliserons une classe de substitution, pour l'exemple, on va utiliser <a href="http://www.phpconcept.net/pclzip/index.php" target="_blank"><font color="#206033" face="Comic Sans MS">pclzip</font></a>.</p>
<p>Maintenant, il faut créer un fichier ZIP (test.zip pour l'exemple) dans lequel on mettra tous nos fichiers à uploader sur le FTP.</p>
<p>Ensuite, il faut créer un fichier php (extract.php pour l'exemple) dans lequel on mettra le code suivant (à adapter selon votre cas) :</p>

<div class="wp_codebox"><table><tr id="p5056"><td class="code" id="p50code56"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Extrait de la documentation de la class.</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pclzip.lib.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$archive</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PclZip<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test.zip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//METTRE LE VRAI NOM DU ZIP ;)</span>
<span style="color: #666666; font-style: italic;">//Extrait dans le repertoire courant.</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$archive</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error : &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$archive</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errorInfo</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>maintenant on se retrouve avec 3 fichiers :</p>
<ol>
<li>extract.php</li>
<li> pclzip.lib.php</li>
<li>test.zip</li>
</ol>
<p>On peut maintenant envoyer nos 3 fichiers dans le répertoire sensé accueillir les fichiers finaux (contenus dans le zip) sur le FTP.</p>
<p>maintenant prendre son navigateur et aller à l'url http://adresse_du_site.free.fr/repertoire/extract.php</p>
<p>et le tour est joué <img src='http://naeh.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>N.B. Cette procédure et valable pour tout hébergement mutualisé (ou pas) ne proposant pas les extensions PHP Zlib ou équivalent.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fnaeh.net%2Fextraire-le-contenu-dun-zip-directement-sur-son-ftp-chez-free%2F&amp;title=Extraire%20le%20contenu%20d%26%23039%3Bun%20zip%20directement%20sur%20son%20FTP%20chez%20free" id="wpa2a_12"><img src="http://naeh.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://naeh.net/extraire-le-contenu-dun-zip-directement-sur-son-ftp-chez-free/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Installer PHPDoc et générer une documentation</title>
		<link>http://naeh.net/installation-phpdoc/</link>
		<comments>http://naeh.net/installation-phpdoc/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 14:33:16 +0000</pubDate>
		<dc:creator>Naeh</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Linux - Logiciels]]></category>
		<category><![CDATA[PHP / MySQL]]></category>
		<category><![CDATA[Programmation]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[pear]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[phpdoc]]></category>
		<category><![CDATA[Serveur]]></category>

		<guid isPermaLink="false">http://naeh.net/installation-phpdoc/</guid>
		<description><![CDATA[Dans cet article nous allons voir comment à partir d'un code source bien commenté, générer une documentation comme on aimerait avoir pour tout projet ou application digne de son nom. Pour cela nous allons utiliser PHPDocumentor. qui va nous permetre de générer une documentation à paritr des sources de notre projet. Il faut d'abord l'installer [...]]]></description>
			<content:encoded><![CDATA[<p>Dans cet article nous allons voir comment à partir d'un code source bien commenté, générer une documentation comme on aimerait avoir pour tout projet ou application digne de son nom.</p>
<p>Pour cela nous allons utiliser <a href="http://www.phpdoc.org/" target="_blank">PHPDocumentor</a>. qui va nous permetre de générer une documentation à paritr des sources de notre projet.</p>
<h2>Il faut d'abord l'installer avec la commande suivante :</h2>

<div class="wp_codebox"><table><tr id="p4860"><td class="code" id="p48code60"><pre class="bash" style="font-family:monospace;">pear <span style="color: #c20cb9; font-weight: bold;">install</span> phpdocumentor</pre></td></tr></table></div>

<p>(si pear n'est pas installé faites un <strong>apt-get install php-pear</strong><em>)</em></p>
<p><em>Si vous rencontrez un problème de dépassement  de mémoire alouée avec PHP, allez dans /etc/php5/cli/php.ini et augmenter cette limite (il s'agit du paramètre memory_limit).</em></p>
<h2>création d'un fichier de configuration pour le projet :</h2>
<p>pour générer la documentation d'un projet nous avons besoin d'un fichier de configuration par projet, en voici un exemple :<br />
fichier nom_du_projet.conf :</p>

<div class="wp_codebox"><table><tr id="p4861"><td class="code" id="p48code61"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>Parse Data<span style="color: #7a0874; font-weight: bold;">&#93;</span>
title = Titre de la documentation
hidden = <span style="color: #c20cb9; font-weight: bold;">false</span>
parseprivate = off
javadocdesc = off
defaultcategoryname = Documentation
defaultpackagename = Projet
target = <span style="color: #000000; font-weight: bold;">/</span>PATH<span style="color: #000000; font-weight: bold;">/</span>OU<span style="color: #000000; font-weight: bold;">/</span>SERA<span style="color: #000000; font-weight: bold;">/</span>ENREGISTRE<span style="color: #000000; font-weight: bold;">/</span>LA<span style="color: #000000; font-weight: bold;">/</span>DOCUMENTATION
readmeinstallchangelog = README, INSTALL, FAQ, LICENSE
directory =   <span style="color: #000000; font-weight: bold;">/</span>PATH<span style="color: #000000; font-weight: bold;">/</span>VERS<span style="color: #000000; font-weight: bold;">/</span>LE<span style="color: #000000; font-weight: bold;">/</span>PROJET
ignore = templates<span style="color: #000000; font-weight: bold;">/</span>,<span style="color: #7a0874; font-weight: bold;">test</span><span style="color: #000000; font-weight: bold;">*</span>.php
sourcecode = on
<span style="color: #007800;">output</span>=HTML:frames:earthli</pre></td></tr></table></div>

<p>et pour tester exécutez la commande suivante (après avoir créé le répertoire cible de la documentation)</p>

<div class="wp_codebox"><table><tr id="p4862"><td class="code" id="p48code62"><pre class="bash" style="font-family:monospace;">phpdoc <span style="color: #660033;">-c</span> nom_du_projet.conf</pre></td></tr></table></div>

<p>et voilà, la génération prend un peu de temps, en fonction de la machine et de la taille du projet.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fnaeh.net%2Finstallation-phpdoc%2F&amp;title=Installer%20PHPDoc%20et%20g%C3%A9n%C3%A9rer%20une%20documentation" id="wpa2a_14"><img src="http://naeh.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://naeh.net/installation-phpdoc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Géolocalisation avec l&#039;API Google et PHP</title>
		<link>http://naeh.net/geolocalisation-avec-lapi-google-et-php/</link>
		<comments>http://naeh.net/geolocalisation-avec-lapi-google-et-php/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 14:05:43 +0000</pubDate>
		<dc:creator>Naeh</dc:creator>
				<category><![CDATA[PHP / MySQL]]></category>
		<category><![CDATA[Programmation]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[développement]]></category>
		<category><![CDATA[geoloc]]></category>
		<category><![CDATA[geolocalisation]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://naeh.net/geolocalisation-avec-lapi-google-et-php/</guid>
		<description><![CDATA[Parmi tous les services que propose les API google, on peut trouver des choses assez intéressantes, surtout en terme de géolocalisation avec l'API google maps et surtout très pratiques, dernièrement j'ai eu l'occasion de travailler avec le web service de géolocalisation, un outil très simple à utiliser et très pratique. le but de la manipulation [...]]]></description>
			<content:encoded><![CDATA[<p>Parmi tous les services que propose les <a href="http://code.google.com/more/#label=APIs">API google</a>, on peut trouver des choses assez intéressantes, surtout en terme de géolocalisation avec l'API google maps et surtout très pratiques, dernièrement j'ai eu l'occasion de travailler avec le <a href="http://code.google.com/apis/maps/documentation/services.html#Geocoding_Direct">web service de géolocalisation</a>, un outil très simple à utiliser et très pratique.</p>
<p>le but de la manipulation est d'obtenir la latitude et la longitude d'un point à partir de son adresse, pour cela, rien de bien méchant :</p>

<div class="wp_codebox"><table><tr id="p4564"><td class="code" id="p45code64"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$address</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'notre adresse'</span> <span style="color: #666666; font-style: italic;">//exemple : 5 rue du taur 31000 Toulouse</span>
&nbsp;
<span style="color: #000088;">$request</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://maps.google.com/maps/geo?'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$request</span> <span style="color: #339933;">.=</span><span style="color: #0000ff;">'q='</span><span style="color: #339933;">.</span><a href="http://www.php.net/urlencode"><span style="color: #990000;">urlencode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$address</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$request</span> <span style="color: #339933;">.=</span><span style="color: #0000ff;">'&amp;key='</span><span style="color: #339933;">.</span>GOOGLE_API_KEY <span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Vous devez en avoir une comme pour toutes les API google.</span>
<span style="color: #000088;">$request</span> <span style="color: #339933;">.=</span><span style="color: #0000ff;">'&amp;output=csv'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on peut choisir d'autres format, c'est très bien expliqué dans lien du web service</span>
&nbsp;
<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// notre réponse est composée de 4 parties.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//exemple de réponse : 200,6,42.730070,-73.690570</span>
<span style="color: #666666; font-style: italic;">//200 code réponse (200 =&gt; ok)</span>
<span style="color: #666666; font-style: italic;">//6 degré de précision</span>
<span style="color: #666666; font-style: italic;">//et les deux dernier sont les coordonnées du point que nous cherchons a géolocaliser.</span></pre></td></tr></table></div>

<p>et voilà avec ce bout de code très simple nous avons géolocalisé une adresse postale, chose très pratique, mais n'oublier pas la limitation qu'impose Google (50 000 requêtes par tranche de 24 heures).</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fnaeh.net%2Fgeolocalisation-avec-lapi-google-et-php%2F&amp;title=G%C3%A9olocalisation%20avec%20l%26%23039%3BAPI%20Google%20et%20PHP" id="wpa2a_16"><img src="http://naeh.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://naeh.net/geolocalisation-avec-lapi-google-et-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Comment convertir un texte en UTF-8</title>
		<link>http://naeh.net/comment-convertir-un-texte-en-utf-8/</link>
		<comments>http://naeh.net/comment-convertir-un-texte-en-utf-8/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 14:04:27 +0000</pubDate>
		<dc:creator>Naeh</dc:creator>
				<category><![CDATA[PHP / MySQL]]></category>
		<category><![CDATA[Programmation]]></category>
		<category><![CDATA[charset]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[decode]]></category>
		<category><![CDATA[encodage]]></category>
		<category><![CDATA[encode]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[utf-8]]></category>

		<guid isPermaLink="false">http://naeh.net/comment-convertir-un-texte-en-utf-8/</guid>
		<description><![CDATA[voici une fonction simple mais efficace pour convertir un texte en UTF-8 sans se préoccuper de sa provenance (encodage d'origine). setlocale&#40;LC_ALL, 'fr_FR.utf8'&#41;; //selon la configuration du serveur cela peut être : fr_FR &#160; mb_detect_order&#40;array&#40;'UTF-8', 'ISO-8859-1', 'ISO-8859-15', 'Windows-1252'&#41;&#41;; //l'extention mb_string est installée par defaut sur php5 function toUTF8&#40;$string&#41;&#123; &#160; $from = mb_detect_encoding&#40;$string&#41;; &#160; if &#40;$from != [...]]]></description>
			<content:encoded><![CDATA[<p>voici une fonction simple mais efficace pour convertir un texte en UTF-8 sans se préoccuper de sa provenance (encodage d'origine).</p>

<div class="wp_codebox"><table><tr id="p4366"><td class="code" id="p43code66"><pre class="php" style="font-family:monospace;"><a href="http://www.php.net/setlocale"><span style="color: #990000;">setlocale</span></a><span style="color: #009900;">&#40;</span>LC_ALL<span style="color: #339933;">,</span> <span style="color: #0000ff;">'fr_FR.utf8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//selon la configuration du serveur cela peut être : fr_FR</span>
&nbsp;
<a href="http://www.php.net/mb_detect_order"><span style="color: #990000;">mb_detect_order</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'UTF-8'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ISO-8859-1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ISO-8859-15'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Windows-1252'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//l'extention mb_string est installée par defaut sur php5</span>
<span style="color: #000000; font-weight: bold;">function</span> toUTF8<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #000088;">$from</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mb_detect_encoding"><span style="color: #990000;">mb_detect_encoding</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$from</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'UTF-8'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
      <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mb_convert_encoding"><span style="color: #990000;">mb_convert_encoding</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'UTF-8'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$from</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fnaeh.net%2Fcomment-convertir-un-texte-en-utf-8%2F&amp;title=Comment%20convertir%20un%20texte%20en%20UTF-8" id="wpa2a_18"><img src="http://naeh.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://naeh.net/comment-convertir-un-texte-en-utf-8/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>L&#039;internationalisation en extension PHP</title>
		<link>http://naeh.net/linternationalisation-en-extension-php/</link>
		<comments>http://naeh.net/linternationalisation-en-extension-php/#comments</comments>
		<pubDate>Sat, 15 Dec 2007 18:52:45 +0000</pubDate>
		<dc:creator>Naeh</dc:creator>
				<category><![CDATA[PHP / MySQL]]></category>
		<category><![CDATA[développement]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[internationalisation]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[langue]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[Programmation]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://naeh.net/index.php/linternationalisation-en-extension-php/</guid>
		<description><![CDATA[L'extension d'internationalisation est de localisation de PHP vient d'être annoncée en version Bêta, elle sera incluse dans PHP 5.3 (encore en développement). Voici les premières classes disponibles : Collator : Manipulation de chaînes ; NumberFormatter : Manipulation de nombres ; Locale : Informations sur la Locale ; Normalizer : Uniformisation de texte en fonction de [...]]]></description>
			<content:encoded><![CDATA[<p>L'extension d'internationalisation est de localisation de PHP vient d'être annoncée en version Bêta, elle sera incluse dans PHP 5.3 (encore en développement).</p>
<p>Voici les premières classes disponibles :</p>
<ul>
<li><strong>Collator</strong> : Manipulation de chaînes ;</li>
<li><strong>NumberFormatter</strong> : Manipulation de nombres ;</li>
<li><strong>Locale</strong> : Informations sur la Locale ;</li>
<li><strong>Normalizer</strong> : Uniformisation de texte en fonction de la locale ;</li>
<li><strong>MessageFormatter</strong> : Construction abstraite de texte à partir des autres objets de l'extension.</li>
</ul>
<p>Collator et FormatNumber permettent de travailler avec des chaînes et avec des nombres, de manière indépendante de la langue (ex : "français") et de la localisation (ex : "fr-CA" ou "fr-FR").<br />
Locale et Normalizer permettent d'intéragir plus en détail avec la localisation et avec du texte <em>localisé</em>.<br />
MessageFormatter est le maître d'orchestre, un nouveau sprintf() en quelque sorte.</p>
<p>L'annonce : <a href="http://php100.wordpress.com/2007/12/12/icuphplove/">http://php100.wordpress.com/2007/12/12/icuphplove/</a><br />
La documentation : <a href="http://docs.php.net/manual/en/book.intl.php">http://docs.php.net/manual/en/book.intl.php</a><br />
Téléchargement : <a href="http://pecl.php.net/package/intl">http://pecl.php.net/package/intl</a></p>
<p>Source : <a href="http://blog.developpez.com/index.php?blog=102&amp;title=l_internationalisation_arrive_enfin_en_e&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1" target="_blank">Developpez.com</a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fnaeh.net%2Flinternationalisation-en-extension-php%2F&amp;title=L%26%23039%3Binternationalisation%20en%20extension%20PHP" id="wpa2a_20"><img src="http://naeh.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://naeh.net/linternationalisation-en-extension-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

