Tuesday, January 24, 2012

Method preg_match() for Cyrillic characters in PHP

Sometimes I encounter the problem with preg_match() method, because it doesn't treat Cyrillic characters the proper way. The problem also corresponds to other non-latin characters.
There is a solution for the search in the string that contains non-latin characters.
<?php 
  preg_match("/^[a-zA-Z\p{Cyrillic}]+$/u", "AбВгд");
?>
Do not forget about the Pattern Modifier - u
u (PCRE_UTF8)

This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern strings are treated as UTF-8.

This modifier is available from PHP 4.1.0 or greater on Unix and from PHP 4.2.3 on win32. UTF-8 validity of the pattern is checked since PHP 4.3.5.

Friday, September 23, 2011

Comparison of float values in PHP

That surprise is not pleasant at all. Especially if you work with money.
<?php
  $a = 0.1 + 0.7;
  $b = 0.8;
  var_dump($a, $b, $a == $b); 

// float(0.8) float(0.8) bool(false) 
?>
To avoid this type of problems let's follow the advice of Richard Johnson, that was published in the April 2013 issue of Web & PHP magazine:
"Be sure you are using ints and working in the smallest non-divisible monetary value (cents or pence). Alternatively make use of the BC or GMP maths functions which can also be useful if you need to do precise decimal operations."

Sunday, September 11, 2011

What php.ini file is used by console

If you are not sure about what php.ini file is used by console, you can find out that by some methods. There is one of them. You can do it by parsing information about php, that will be displayed by php -i.
php -i | grep php\.ini
or
find / -name php.ini 

Monday, June 27, 2011

ACL - access control list

An access control list (ACL), with respect to a computer file system, is a list of permissions attached to an object. An ACL specifies which users or system processes are granted access to objects, as well as what operations are allowed on given objects. Each entry in a typical ACL specifies a subject and an operation. For instance, if a file has an ACL that contains (Alice, delete), this would give Alice permission to delete the file. (c) wikipedia There is a useful article from Symfony tutorial with good explanation http://symfony.com/doc/current/cookbook/security/acl_advanced.html

Friday, June 24, 2011

Некоторые настройки стандартного набора Symfony под Ubuntu

Некоторые установки, которые понадобились мне при настройке стандартного набора Symfony под Ubuntu.

Установка PHP Accelerator (APC)
sudo apt-get install php-apc
sudo apt-get install php5-intl
sudo service apache2 restart