Shared snippet, command, script ...2014-06-23T12:04:11+02:00https://shaarlet.knah-tsaeb.org/https://shaarlet.knah-tsaeb.org/https://shaarlet.knah-tsaeb.org/Echanger les valeurs de plusieurs variableshttps://shaarlet.knah-tsaeb.org/?vdZBGQ2014-06-23T12:04:11+02:00</br><code>list($a, $b) = array($b, $a);</code></br> via (<a href="https://shaarlet.knah-tsaeb.org/?vdZBGQ">Permalink</a>)Ajouter http à une URL si nécessairehttps://shaarlet.knah-tsaeb.org/?KAy0-A2013-05-13T16:10:42+02:00Une petite function bien pratique lorsque l'on doit traiter des urls.</br><code>function add_protocol($url,$protocol='http://'){<br />
if (preg_match('#^([ftphs]+://)([^ ]+)#',$url,$results)){return $url;}else{return $protocol.$url;}<br />
}</code></br> via <a href="http://www.warriordudimanche.net/article156/ajouter-http-a-une-url-si-necessaire" rel="nofollow">http://www.warriordudimanche.net/article156/ajouter-http-a-une-url-si-necessaire</a><br>(<a href="https://shaarlet.knah-tsaeb.org/?KAy0-A">Permalink</a>)[php] Loguer toutes les requêtes GET et POSThttps://shaarlet.knah-tsaeb.org/?8degDg2013-04-22T09:46:31+02:00Pour déboguer une appli php, voici un petit snippet qui loguera dans un fichier toutes les requêtes GET/POST et leur contenu. C'est tout bête mais ça peut servir.</br><code>function logm($message) {<br />
$t = strval(date('Y/m/d_H:i:s')).' - '.$_SERVER["REMOTE_ADDR"].' - '.strval($message)."\n";<br />
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/log.txt',$t,FILE_APPEND);<br />
}<br />
if (!empty($_POST)) logm('POST: '.print_r($_POST, true));<br />
if (!empty($_GET)) logm('GET: '.print_r($_GET, true));</code></br> via <a href="http://sebsauvage.net/links/?L1p_sg" rel="nofollow">http://sebsauvage.net/links/?L1p_sg</a><br>(<a href="https://shaarlet.knah-tsaeb.org/?8degDg">Permalink</a>)Améliore la sortie print_rhttps://shaarlet.knah-tsaeb.org/?HsF04A2013-03-14T14:19:41+01:00Une fonction bien pratique pour aidé au débogage.<br />
<br />
$maVar : peut être n'importe quoi (array,variable,objet)<br />
nom_a_affiché : c'est simplement pour mieux s'y retrouver lorsque l'on appelle plusieurs fois la fonction par page.<br />
<br />
n_print($maVar,'nom a affiché');</br><code><?php<br />
/**<br />
* Améliore la sortie print<br />
*<br />
* @author Tatane <a href="http://www.tatane.info/index.php/print_rn" rel="nofollow">http://www.tatane.info/index.php/print_rn</a><br />
* @author <a href="http://www.blog.cactuscrew.com/77-print_rn.html" rel="nofollow">http://www.blog.cactuscrew.com/77-print_rn.html</a><br />
* @param $data (array) tableau ou variable à examiner<br />
* @param $name (string) nom a afficher<br />
* @return false affiche les clef valeur du tableau $data<br />
* @example n_print($array, 'Tableau de valeur');<br />
*/<br />
function n_print($data, $name = '') {<br />
$aBackTrace = debug_backtrace();<br />
echo '<h2>', $name, '</h2>';<br />
echo '<fieldset style="border: 1px solid orange; padding: 5px;color: #333; background-color: #fff;">';<br />
echo '<legend style="border:1px solid orange;padding: 1px;background-color:#eee;color:orange;">', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], '</legend>';<br />
echo '<pre>', htmlentities(print_r($data, 1)), '</pre>';<br />
echo '</fieldset><br />';<br />
}</code></br> via <a href="http://www.blog.cactuscrew.com/77-print_rn.html" rel="nofollow">http://www.blog.cactuscrew.com/77-print_rn.html</a><br>(<a href="https://shaarlet.knah-tsaeb.org/?HsF04A">Permalink</a>)Remplacer les accents dans une chaine de caractèreshttps://shaarlet.knah-tsaeb.org/?tecNFw2013-02-11T10:26:42+01:00Remplace les caractères accentué dans une chaine par leurs équivalent non accentué (é => e).</br><code>// le classique<br />
$texte = strtr($texte, '@ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', 'aAAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');<br />
<br />
// et le petit plus de Timo<br />
$texte = preg_replace('#&(.)(acute|grave|circ|uml|cedil|tilde|ring|slash|caron);#', '$1', $texte);</code></br> via <a href="http://lehollandaisvolant.net/?mode=links&id=20130209141245" rel="nofollow">http://lehollandaisvolant.net/?mode=links&id=20130209141245</a><br>(<a href="https://shaarlet.knah-tsaeb.org/?tecNFw">Permalink</a>)