Brutal fix for “Incorrect string value:” error in Matomo (Piwik)

If you’re using Matomo (previously Piwik) on MS IIS and MariaDB  and you’re getting a lot of these:

[06-Jun-2018 11:56:36 UTC] Error in Matomo (tracker): Error query: SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value: '\xC3_\xC6\x92\xC3\x82...' for column 'name' at row 1 In query: INSERT INTO matomo_log_action (name, hash, type, url_prefix) VALUES (?,CRC32(?),?,?) Parameters: array (   0 => 'Ă_ƒÂ¢',   1 => 'Ă_ƒÂ¢',   2 => 1,   3 => 1, )

You can use my fix (because literally nothing that can be found in the internet is helpful in this case).

Continue reading Brutal fix for “Incorrect string value:” error in Matomo (Piwik)

E-mail extraction from an Outlook copied string

Sometimes you need to extract an e-mail address from a format like this:

Name Surname <[email protected]>

In such cases use this function:

 * Extract mail address from a string
 * @param string $emailString
 * @return mixed match on success, false on error
function extractEmail( $emailString ) {
    /** @var string $result **/
    $result = preg_match( '/^(?:[\w.\- ]+<)?([\w._-][email protected][\da-z\.-]+\.[a-z\.]{2,6})>?$/iu', $emailString, $matches );
    if( $result === 1 || $result !== false ) {
        return $matches[1];
    } else {
        return false;

Link to test regular expression used by me is here.

Differences between character counting in PHP and Javascript

I’ve recently codded my own validation rules for forms. I’m checking length of a string on a client side and also on a server side (obviously it’s a good practice). After my script went on a production, users started to complain about validation errors (even if data in a form was passed proper). This is really strange but…
Continue reading Differences between character counting in PHP and Javascript

Smarty gettext with domain support (block t plugin) [depreciated]

Attention! Official Gettext plugin for Smarty has domain support since version 1.1. Check official repository:


This is a Smarty gettext plugin modification. It enables domain support and utilize gettext wrapper for PHP,

Why do I use such wrapper for a gettext? It’s simple, not every server has native support for translation. This crafty script gives you fallback in case if it does not.

Usage example:

Init before any template parsed by Smarty:

// include gettext wrapper for PHP
// set locale
T_setlocale(LC_MESSAGES, 'en_US');
// load lang file
/* loads ./lang/en_US/LC_MESSAGES/ (do not close path with final slash) */
T_bindtextdomain('example', './lang'); 
T_bind_textdomain_codeset('example', 'utf-8'); /* just in case */ 
// set default domain 

Smarty syntax example:

{t domain="example"}This text will be translated using gettext domain example.{/t}
{t}This text will be translated using standard gettext domain.{/t}


Simply put file block.t.php into Smarty plugins directory.