Nov 11 2010

Splitting string at capitalized letters

Category: Articles,Code snippets,PHP,PHPFractalizeR @ 7:42 pm

Recently I had a task to split a given string at capitalized characters, having those saved in PHP. I’ve invented the following solution:

<?php
$str = 'TestMyFuncCall';
var_dump(preg_split('/(?=[A-Z])/', $str, null, PREG_SPLIT_NO_EMPTY));

The result is:

array(4) {
  [0]=>
  string(4) "Test"
  [1]=>
  string(2) "My"
  [2]=>
  string(4) "Func"
  [3]=>
  string(4) "Call"
}

I utilize regular expressions assertions here to avoid character loss.


Sep 27 2010

Regular expression for russian letters in UTF-8

Category: Articles,Code snippets,PHP,PHPFractalizeR @ 1:27 pm
(\xD0[\x80-\xBF])|(\xD1[\x80-\xBF])


Jul 03 2009

PHP Array of ISO 639-1 language codes => names.

Category: Code snippets,PHPFractalizeR @ 4:43 pm

Hello. For purposes of writting scripts for converting data formats, I have constructed an array, that can be used to replace language codes by their names.

Continue reading “PHP Array of ISO 639-1 language codes => names.”

Tags: , , , ,