Skip to content

Instantly share code, notes, and snippets.

@themactep
Created June 30, 2010 07:21
Show Gist options
  • Save themactep/458356 to your computer and use it in GitHub Desktop.
Save themactep/458356 to your computer and use it in GitHub Desktop.
<?php
// php equivalent of ruby one-liner
// "строка текста!".chars.to_a.last
function u_str_split($string, $split_length=1)
{
preg_match_all('`.`u', $string, $arr);
$arr = array_chunk($arr[0], $split_length);
$arr = array_map('implode', $arr);
return $arr;
}
$str = "строка текста!";
$chars = u_str_split($str);
$len = sizeof($chars);
echo $chars[$len - 1];
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment