Cannot work with cyrillics in php

php

#1

Hello everybody!

Discovered that my workspace doesn’t support cyrillic options. Working on a small test project written on php and just stuck (( Most of php string functions (e.g. strstr, strtoupper) don’t work with cyrillic symbols. For example, such a code

<?php

$date = "12 июля";
$upperdate = strtoupper($date);
echo "$upperdate\n";

?>

returns lowercase string ((

Worse things happen when I try to read from cyrillic txt files via fgetc, fgets or fgetcsv: cyrillic strings and arrays all turn to garbage and cannot be parsed and operated on properly.

setlocale(), iconv(), iconv_set_encoding() dont help a bit ((

Please advice.


#2

Check out the manual for the multi byte string functions:

http://php.net/manual/en/ref.mbstring.php

<?php
$date = "12 июля";
$upperdate = mb_strtoupper($date, 'UTF-8');
echo "$upperdate\n";

#3

Well, yeah, it is the correct answer, but it doesn’t help anyhow because default C9 web server doesn’t include mbstring library to call for this function. If you search through this forum you will find howto on installing this library, but it is also irrelevant because c9 uses yum instead of apt-get. And if you simply try to execute sudo yum install php-mbstring it will cause a conflict. The sollution I found here.
So simly type sudo yum install php56-mbstring in bash. Consider that phpversion might change.