<?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>piouPiouM&#039;s dev&#187; Archives pour le tag convertir – piouPiouM&#039;s dev</title>
	<atom:link href="http://pioupioum.fr/tag/convertir/feed/" rel="self" type="application/rss+xml" />
	<link>http://pioupioum.fr</link>
	<description>Bloc-note d&#039;un développeur web</description>
	<lastBuildDate>Thu, 05 Aug 2010 13:48:33 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>TextMate&#160;: convertir une couleur hexadécimale en notation RGBA</title>
		<link>http://pioupioum.fr/outils-astuces/textmate-convertir-couleur-hexadecimale-html-rgba.html</link>
		<comments>http://pioupioum.fr/outils-astuces/textmate-convertir-couleur-hexadecimale-html-rgba.html#comments</comments>
		<pubDate>Thu, 15 Apr 2010 10:19:56 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Outils, trucs et astuces]]></category>
		<category><![CDATA[convertir]]></category>
		<category><![CDATA[couleur]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[licence MIT]]></category>
		<category><![CDATA[rgba]]></category>
		<category><![CDATA[TextMate]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=367</guid>
		<description><![CDATA[CSS supporte divers formats de description des couleurs, le plus utilisé étant la notation héxadécimale #RRGGBB. L&#8217;introduction du support des couleurs RGBA par CSS 3 a été l&#8217;occasion pour certains de découvrir les notations rgba(255, 255, 255, 1) et sa version sans gestion de l&#8217;opacité rgb(255, 255, 255).

Il faut avouer que si nous disposons d&#8217;une [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>CSS supporte divers formats de description des couleurs, le plus utilisé étant la <strong>notation héxadécimale</strong> <code>#RRGGBB</code>. L&#8217;introduction du support des <a href="http://pioupioum.fr/tag/rgba/" title="Archives pour le tag rgba – piouPiouM&#039;s dev">couleurs RGBA</a> par CSS 3 a été l&#8217;occasion pour certains de découvrir les notations <code>rgba(255, 255, 255, 1)</code> et sa version sans gestion de l&#8217;opacité <code>rgb(255, 255, 255)</code>.</p>

<p>Il faut avouer que si nous disposons d&#8217;une palette d&#8217;outils d&#8217;aide à la saisie de couleurs en notation hexadécimale, il en est rien pour insérer une couleur au format <code>rgb[a]</code>, et cela peut <a href="http://twitter.com/br1o/status/12041847261" title="une réaction sur twitter">agacer</a>. Mais c&#8217;était sans compter sur <a href="http://pioupioum.fr/tag/textmate/" title="Archives pour le tag TextMate – piouPiouM&#039;s dev">TextMate</a>&#160;!<span id="more-367"></span></p>

<h2>Convertir une couleur héxadécimale en notation RGBA</h2>

<p>La commande TextMate <strong>Convert Hex to RGB(A) color</strong> va vous permettre de convertir <em>via</em> le raccourci clavier <kbd>⌘⇧X</kbd> une couleur héxadécimale en son équivalent RGB(A).</p>

<h3>Installation</h3>

<p>Après avoir téléchargé le fichier qui suit, installez la commande d&#8217;un simple double-clique.</p>

<div class="box textmate-command">
    <a title="Télécharger" href="http://assets1.pioupioum.fr/uploads/2010/04/Convert-Hex-to-RGBA-color.tmCommand"><span>Convert Hex to RGB(A) color.tmCommand (4&#160;Ko)</span></a>
</div>

<p>La nouvelle commande est maintenant disponible dans le bundle <strong>Source</strong>.</p>

<p>Pourquoi l&#8217;installer dans le bundle <strong>Source</strong> au lieu du bundle <strong>CSS</strong>&#160;? Parce qu&#8217;elle peut être utile dans d&#8217;autre languages, comme JavaScript et sera ainsi disponible à tout moment, qu&#8217;importe le bundle actif.</p>

<h3>Usage</h3>

<p>Simple d&#8217;utilisation, positionnez-vous sur une couleur et activez la commande pour obtenir son équivalent en notation RGB&#160;:</p>

<pre>#6633ff => rgb(102, 51, 255)
#63F    => rgb(102, 51, 255)</pre>

<p>Ajoutez à une couleur héxadécimale la composante d&#8217;opacité pour remplacer la couleur par sa forme RGBA&#160;:</p>

<pre>#6633FF80 => rgba(102, 51, 255, .50)
#63FA     => rgba(102, 51, 255, .67)
#63F0     => rgba(102, 51, 255, 0)</pre>

<p>Vous pouvez également sélectionner une couleur (avec le sharp <code>#</code> initial) et lancer la convertion. Cela se révèle être particulièrement utile avec une sélection en colonne.</p>

<h3>Code source</h3>

<p>Voici le <a href="http://gist.github.com/366816" title="gist: 366816 - Source code of a TextMate Command- GitHub">code</a> ruby<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> utilisé au sein de la commande.
<script src="http://gist.github.com/366816.js?file=hex2rgba.rb"></script></p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/developpement/jquery-color-plugin-animation-rgba-support.html' title='Du RGBA dans vos animations avec le plugin jQuery Color'>Du RGBA dans vos animations avec le plugin jQuery Color</a></li><li><a href='http://pioupioum.fr/developpement/javascript-detecter-support-rgba.html' title='JavaScript : tester le support des couleurs RGBA'>JavaScript&#160;: tester le support des couleurs RGBA</a></li><li><a href='http://pioupioum.fr/outils-astuces/license-helper-textmate-bundle.html' title='Bundle License Helper pour TextMate'>Bundle License Helper pour TextMate</a></li><li><a href='http://pioupioum.fr/snippets/textmate-commande-exporter-mots-word-wrap.html' title='TextMate : commande &laquo;&nbsp;Export words&nbsp;&raquo;'>TextMate&#160;: commande &laquo;&nbsp;Export words&nbsp;&raquo;</a></li><li><a href='http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html' title='PHP : convertir un DATETIME en un timestamp UNIX'>PHP&#160;: convertir un DATETIME en un timestamp UNIX</a></li></ul>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>Toute remarque ou conseil est le bienvenu. Il s&#8217;agit de mon premier script ruby…&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/outils-astuces/textmate-convertir-couleur-hexadecimale-html-rgba.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP&#160;: convertir un DATETIME en un timestamp UNIX</title>
		<link>http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html</link>
		<comments>http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html#comments</comments>
		<pubDate>Tue, 09 Mar 2010 23:28:01 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[convertir]]></category>
		<category><![CDATA[licence MIT]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=346</guid>
		<description><![CDATA[Mise à jour à 10:57
Plus simple, rapide, intégré, toussa&#160;: utiliser strtotime tout simplement.
Merci à Éric Daspet et à Oncle Tom pour le rappel.

Une fonction utilitaire1 pour convertir une chaîne de type DATETIME ou DATE en un timestamp UNIX.
Les formats pris en charges en entrée sont AAAA-MM-JJ HH:MM:SS et AA-MM-JJ HH:MM:SS. L&#8217;heure étant optionnelle dans le [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p><strong>Mise à jour à 10:57</strong><br />
Plus simple, rapide, intégré, toussa&#160;: utiliser <a href="http://php.net/manual/fr/function.strtotime.php">strtotime</a> tout simplement.<br />
Merci à <a href="http://twitter.com/edasfr/status/10264669320" title="réaction sur twitter">Éric Daspet</a> et à <a href="http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html#comment-1187" title="réaction dans les commentaires">Oncle Tom</a> pour le rappel.</p>

<p>Une fonction utilitaire<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> pour convertir une chaîne de type <strong>DATETIME</strong> ou <strong>DATE</strong> en un <strong>timestamp UNIX</strong>.<br />
Les formats pris en charges en entrée sont <code>AAAA-MM-JJ HH:MM:SS</code> et <code>AA-MM-JJ HH:MM:SS</code>. L&#8217;heure étant optionnelle dans le cas de la conversion d&#8217;une date.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * Get UNIX timestamp for a date or date time.
 *
 * Example:
 * &lt;code&gt;
 * &lt;?php
 * unix_timestamp('2010-03-09 22:43:46'); # 1268171026
 * unix_timestamp('10-03-09 22:43:46');   # 1268171026
 * unix_timestamp('2010-03-09');          # 1268089200
 * ?&gt;
 * &lt;/code&gt;
 *
 * @author    Mehdi Kabab &lt;http://pioupioum.fr/&gt;
 * @copyright 2010 Mehdi Kabab
 * @license   http://www.opensource.org/licenses/mit-license.html MIT License
 * @link      http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html
 *
 * @param string The date or datetime to convert.
 * @return int The UNIX timestamp corresponding to the datetime.
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> unix_timestamp<span style="color: #009900;">&#40;</span><span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$date</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: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'-'</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: #000088;">$c</span>    <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'-'</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: #000088;">$c</span>    <span style="color: #339933;">=</span> <span style="color: #990000;">array_pad</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">array_walk</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'intval'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/snippets/php-uncamel-fonction-convertir-camel-case.html' title='PHP : fonction uncamel() pour inverser une notation en CamelCase'>PHP&#160;: fonction uncamel() pour inverser une notation en CamelCase</a></li><li><a href='http://pioupioum.fr/snippets/textmate-commande-exporter-mots-word-wrap.html' title='TextMate : commande &laquo;&nbsp;Export words&nbsp;&raquo;'>TextMate&#160;: commande &laquo;&nbsp;Export words&nbsp;&raquo;</a></li><li><a href='http://pioupioum.fr/outils-astuces/textmate-convertir-couleur-hexadecimale-html-rgba.html' title='TextMate : convertir une couleur hexadécimale en notation RGBA'>TextMate&#160;: convertir une couleur hexadécimale en notation RGBA</a></li><li><a href='http://pioupioum.fr/outils-astuces/license-helper-textmate-bundle.html' title='Bundle License Helper pour TextMate'>Bundle License Helper pour TextMate</a></li><li><a href='http://pioupioum.fr/developpement/javascript-array-intersection.html' title='JavaScript : optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles'>JavaScript&#160;: optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles</a></li></ul>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>vous allez dire qu&#8217;il en existe pléthore, mais je les trouve toutes trop lourdes (conditions, strlen, multiples explode, etc) pour le peu à faire. Sans parler du fait qu&#8217;elles ne supportent uniquement que le format DATETIME.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Bash&#160;: convertir un string en entier</title>
		<link>http://pioupioum.fr/snippets/bash-convertir-string-to-integer.html</link>
		<comments>http://pioupioum.fr/snippets/bash-convertir-string-to-integer.html#comments</comments>
		<pubDate>Sat, 06 Mar 2010 19:06:25 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[convertir]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=340</guid>
		<description><![CDATA[Bash n&#8217;offre pas de fonction pour convertir une chaîne de caractères ou un nombre flottant en un entier.
Cela n&#8217;est toute fois pas impossible, il suffit de faire appel à printf1 et le tour est joué&#160;!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env bash
# string_to_int.sh - Shell script to convert a string or float number
# to an integer.
&#160;
function string_to_int &#40;&#41;
&#123;
    [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p><a href="http://fr.wikipedia.org/wiki/Bourne-Again_shell" title="Bourne-Again shell - Wikipédia">Bash</a> n&#8217;offre pas de fonction pour convertir une chaîne de caractères ou un nombre flottant en un entier.<br />
Cela n&#8217;est toute fois pas impossible, il suffit de faire appel à <code>printf</code><sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> et le tour est joué&#160;!</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/env bash</span>
<span style="color: #666666; font-style: italic;"># string_to_int.sh - Shell script to convert a string or float number</span>
<span style="color: #666666; font-style: italic;"># to an integer.</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> string_to_int <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">LANG</span>=C
    <span style="color: #007800;">d</span>=<span style="color: #800000;">${1##*.}</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${#1}</span> <span style="color: #660033;">-eq</span> <span style="color: #800000;">${#d}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">d</span>=<span style="color: #000000;">0</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #007800;">e</span>=<span style="color: #800000;">${1%.*}</span>
    <span style="color: #007800;">e</span>=<span style="color: #800000;">${e//,/}</span>
    <span style="color: #7a0874; font-weight: bold;">printf</span> <span style="color: #000000; font-weight: bold;">%</span>.0f <span style="color: #ff0000;">&quot;<span style="color: #007800;">$e</span>.<span style="color: #007800;">$d</span>&quot;</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #007800;">not_int</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;12.652&quot;</span> <span style="color: #ff0000;">&quot;-12.652&quot;</span> <span style="color: #000000;">12.652</span> <span style="color: #000000;">14</span> <span style="color: #ff0000;">&quot;12,652&quot;</span> foo <span style="color: #ff0000;">&quot;1,254.8&quot;</span> <span style="color: #000000;">1</span>,<span style="color: #000000;">254.8</span> <span style="color: #ff0000;">&quot;125,160,254.8&quot;</span> <span style="color: #ff0000;">&quot;125,160,254&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> value <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${not_int[@]}</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Convert <span style="color: #007800;">$value</span> to int: <span style="color: #007800;">$(string_to_int $value)</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>


<p>Ce qui nous donne&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>string_to_int.sh 
Convert <span style="color: #000000;">12.652</span> to int: <span style="color: #000000;">13</span>
Convert -<span style="color: #000000;">12.652</span> to int: <span style="color: #660033;">-13</span>
Convert <span style="color: #000000;">12.652</span> to int: <span style="color: #000000;">13</span>
Convert <span style="color: #000000;">14</span> to int: <span style="color: #000000;">14</span>
Convert <span style="color: #000000;">12</span>,<span style="color: #000000;">652</span> to int: <span style="color: #000000;">12652</span>
Convert foo to int: <span style="color: #000000;">0</span>
Convert <span style="color: #000000;">1</span>,<span style="color: #000000;">254.8</span> to int: <span style="color: #000000;">1255</span>
Convert <span style="color: #000000;">1</span>,<span style="color: #000000;">254.8</span> to int: <span style="color: #000000;">1255</span>
Convert <span style="color: #000000;">125</span>,<span style="color: #000000;">160</span>,<span style="color: #000000;">254.8</span> to int: <span style="color: #000000;">125160255</span>
Convert <span style="color: #000000;">125</span>,<span style="color: #000000;">160</span>,<span style="color: #000000;">254</span> to int: <span style="color: #000000;">125160254</span></pre></div></div>


<p>Voir <a href="http://gist.github.com/324313">sur Github</a>.</p>

<p><strong>Mis à jour le 7 mars 2010</strong><br />
Prise en charge de la notation US. Merci à <a href="http://pioupioum.fr/snippets/bash-convertir-string-to-integer.html#comment-1159">patpro</a>.</p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/outils-astuces/textmate-convertir-couleur-hexadecimale-html-rgba.html' title='TextMate : convertir une couleur hexadécimale en notation RGBA'>TextMate&#160;: convertir une couleur hexadécimale en notation RGBA</a></li><li><a href='http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html' title='PHP : convertir un DATETIME en un timestamp UNIX'>PHP&#160;: convertir un DATETIME en un timestamp UNIX</a></li><li><a href='http://pioupioum.fr/snippets/php-uncamel-fonction-convertir-camel-case.html' title='PHP : fonction uncamel() pour inverser une notation en CamelCase'>PHP&#160;: fonction uncamel() pour inverser une notation en CamelCase</a></li><li><a href='http://pioupioum.fr/snippets/convertir-icone-icns-png.html' title='Convertir une icône ICNS en une image PNG'>Convertir une icône ICNS en une image PNG</a></li><li><a href='http://pioupioum.fr/snippets/leopard-rechercher-nom-reel-utilisateur.html' title='Rechercher le nom réel d&#8217;un utilisateur sous Leopard'>Rechercher le nom réel d&#8217;un utilisateur sous Leopard</a></li></ul>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>une substitution du séparateur des décimals <code>.</code> en <code>,</code> est nécessaire avant de faire appel à <code>printf</code>.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/snippets/bash-convertir-string-to-integer.html/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP&#160;: fonction uncamel() pour inverser une notation en CamelCase</title>
		<link>http://pioupioum.fr/snippets/php-uncamel-fonction-convertir-camel-case.html</link>
		<comments>http://pioupioum.fr/snippets/php-uncamel-fonction-convertir-camel-case.html#comments</comments>
		<pubDate>Sun, 28 Feb 2010 18:17:12 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[convertir]]></category>
		<category><![CDATA[gist]]></category>
		<category><![CDATA[licence MIT]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=336</guid>
		<description><![CDATA[Une fonction PHP utilitaire pour convertir une chaîne en notation CamelCase en mots réunis par un séparateur (par défaut, le caractère underscore _).

La fonction uncamel() supporte indifféremment, en entrée, les notations lowerCamelCase et UpperCamelCase.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
&#60;?php
/**
 * Reverse a CamelCase string.
 *
 * Examples:
 *     uncamel('lowerCamelCase') === 'lower_camel_case'
 *     [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Une fonction <strong><a href="http://fr.wikipedia.org/wiki/PHP" title="PHP: Hypertext Preprocessor - Wikipédia">PHP</a></strong> utilitaire pour convertir une chaîne en notation <strong><a href="http://fr.wikipedia.org/wiki/CamelCase" title="CamelCase - Wikipédia">CamelCase</a></strong> en mots réunis par un séparateur (par défaut, le caractère <em>underscore</em> <code>_</code>).</p>

<p>La fonction <strong><code>uncamel()</code></strong> supporte indifféremment, en entrée, les notations <strong>lowerCamelCase</strong> et <strong>UpperCamelCase</strong>.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * Reverse a CamelCase string.
 *
 * Examples:
 *     uncamel('lowerCamelCase') === 'lower_camel_case'
 *     uncamel('UpperCamelCase') === 'upper_camel_case'
 *     uncamel('ThisIsAString') === 'this_is_a_string'
 *     uncamel('notcamelcase') === 'notcamelcase'
 *     uncamel('lowerCamelCase', ' | ') === 'lower | camel | case'
 *
 * @author    Mehdi Kabab &lt;http://pioupioum.fr/&gt;
 * @copyright 2010 Mehdi Kabab
 * @license   http://www.opensource.org/licenses/mit-license.html MIT License
 * @link      http://pioupioum.fr/snippets/php-uncamel-fonction-convertir-camel-case.html
 *
 * @param  string $content The CamelCase string.
 * @param  string $separator The glue for the compound words. Defaults to '_'.
 * @return string
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> uncamel<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #339933;">,</span> <span style="color: #000088;">$separator</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: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#(?&lt;=[a-zA-Z])([A-Z])(?=[a-zA-Z])#e'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;'<span style="color: #006699; font-weight: bold;">$separator</span>' . strtolower('<span style="color: #006699; font-weight: bold;">$1</span>')&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$content</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: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>


<p>Le <a href="http://gist.github.com/317702" title="gist: 317702 -  GitHub">forker (gist)</a>.</p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html' title='PHP : convertir un DATETIME en un timestamp UNIX'>PHP&#160;: convertir un DATETIME en un timestamp UNIX</a></li><li><a href='http://pioupioum.fr/snippets/textmate-commande-exporter-mots-word-wrap.html' title='TextMate : commande &laquo;&nbsp;Export words&nbsp;&raquo;'>TextMate&#160;: commande &laquo;&nbsp;Export words&nbsp;&raquo;</a></li><li><a href='http://pioupioum.fr/outils-astuces/textmate-convertir-couleur-hexadecimale-html-rgba.html' title='TextMate : convertir une couleur hexadécimale en notation RGBA'>TextMate&#160;: convertir une couleur hexadécimale en notation RGBA</a></li><li><a href='http://pioupioum.fr/outils-astuces/license-helper-textmate-bundle.html' title='Bundle License Helper pour TextMate'>Bundle License Helper pour TextMate</a></li><li><a href='http://pioupioum.fr/developpement/javascript-array-intersection.html' title='JavaScript : optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles'>JavaScript&#160;: optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles</a></li></ul>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/snippets/php-uncamel-fonction-convertir-camel-case.html/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
