Outils pour utilisateurs

Outils du site


informatique:php:tips

Ceci est une ancienne révision du document !


PHP Tips & Tricks

DateTime

Php => Mysql => Php

 $mysqldate = date( 'Y-m-d H:i:s', $phpdate );

 $phpdate = strtotime( $mysqldate );

strftime

le paramètre %e pour mettre le jour du mois sur 1 seul chiffre (1 à 31) ne fonctionne pas avec Php/Windows. La raison est que strftime n'est pas portable et la doc php n'est donc pas correcte pour tous les OS.

Voir:

La solution pour le %e : remplacer par “%#d”

Gestion des erreurs

Exception

Sécurité

Strong cryptography in PHP: Use standard algorithms, Key space, Kerchoof’s principle, Don’t use rand() or mt_rand(), Use a salt value in hash functions, Size and strength of the passwords, Don’t use plaintext passwords as key for ciphers, Use Base64 to encode encrypted data.

Divers

DocComment & ReflectionClass

Une démonstration de la récupération des commentaires Advanced Documentation With Reflection In PHP 5, mais obsolète car utilise la fonction php_check_syntax() qui n'est plus dans php depuis php 5.0.4

phpDocumentor home page

See the example at de3.php.net/manual/en/reflectionclass.getdoccomment.php - if you want to parse files for classes, you can use github.com/theseer/Autoload/blob/master/src/classfinder.php and to iterate over directories you use de3.php.net/manual/en/class.recursivedirectoryiterator.php

RegEx

Validation syntaxe adresse email :

function mail_checksyntax( $email )
{
  if( isset($email)
  && eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$', $email) )
  {
    return true ;
  }
  return false ;
}

Cross Platform

if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) {
  $s_eol = "\r\n";
} elseif (strtoupper(substr(PHP_OS, 0, 3) == 'MAC')) {
  $s_eol = "\r";
} else {
  $s_eol = "\n";
}

XML

XSLT

<xsl:text disable-output-escaping="yes"> &amp;nbsp;</xsl:text>

fonctionne mieux que CDATA …

Pointeur de fonction

Singleton

Manipulation fichier Excel

Introduction à PHPExcel par Ernaelsten Gérard (05/02/2009)

Le package Spreadsheet_Excel_Writer

/usr/local/php5/bin/pear -d preferred_state=beta install OLE
/usr/local/php5/bin/pear -d preferred_state=beta install Spreadsheet_Excel_Writer

Mysqlnd

mysqlnd plugins for PHP in practice: example on how to write a plugin for mysqlnd.

PHP: Transparent load balancing and sharding with mysqlnd: You want some client-side MySQL load balancing with and without sharding for your PHP application? PHP 5.3 has something to offer for you. It is free. It requires no to very little changes to your applications.

informatique/php/tips.1297867329.txt.gz · Dernière modification : 19/05/2012 00:15 (modification externe)

Sauf mention contraire, le contenu de ce wiki est placé sous les termes de la licence suivante : CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki