<?php
// mbstring_test.php
// RJM Programming
// July, 2015
function mb_str_split( $string ) { // thanks to http://php.net/manual/en/function.mb-split.php
    # Split at all position not after the start: ^
    # and not before the end: $
    return preg_split('/(?<!^)(?!$)/u', $string );
}

try {
mb_internal_encoding( 'UTF-8');
mb_regex_encoding( 'UTF-8');  
} catch (Exception $e) { }

$string   = '火车票'; // Train tickets
$charlist = str_split( $string );
$vscharlist = mb_str_split( $string );
try {
$stop   = mb_strlen( $string);
$vsvscharlist = array();

for( $idx = 0; $idx < $stop; $idx++)
{
   $vsvscharlist[] = mb_substr( $string, $idx, 1);
} 
} catch (Exception $ee) {
$vsvscharlist = $vscharlist;
}
?>
<html>
<head>
<meta charset="utf-8">
<link href='//www.rjmprogramming.com.au/PHP/emboss_h1.css' rel='stylesheet' type='text/css'>
<title>Showing mb_strlen and mb_substr for 火车票 - RJM Programming - July, 2015</title>
<script type='text/javascript'>

var eall_c, etrain_c, etickets_c, call_e, c1_e, c2_e, c3_e;

function wourl(theurl, t, l, w, h, varname) {
  eval(varname + " = window.open('" + theurl + "','_blank','top=" + t + ",left=" + l + ",width=" + w + ",height=" + h + "')"); 
}

<?php
  echo "\n wourl('https://translate.google.com/#en/zh-CN/Train%20tickets', 400, 100, 500, 300, 'eall_c'); \n";
  echo "\n wourl('https://translate.google.com/#en/zh-CN/Train', 400, 600, 450, 300, 'etrain_c'); \n";
  echo "\n wourl('https://translate.google.com/#en/zh-CN/tickets', 550, 100, 450, 300, 'etickets_c'); \n";
  echo "\n wourl('https://translate.google.com/#zh-CN/en/火车票', 550, 550, 500, 300, 'call_e'); \n";
  echo "\n wourl('https://translate.google.com/#zh-CN/en/火', 700, 100, 450, 300, 'c1_e'); \n";
  echo "\n wourl('https://translate.google.com/#zh-CN/en/车', 700, 550, 450, 300, 'c2_e'); \n";
  echo "\n wourl('https://translate.google.com/#zh-CN/en/票', 700, 1000, 450, 300, 'c3_e'); \n";
?>

</script>
</head>
<body style='background-color: orange;'>
<h1 align='center'>Showing mb_strlen and mb_substr for 火车票</h1>
<div align='center'>
<p><?php echo "Using str_split: "; print_r( $charlist ); ?></p><p><?php echo "Using 'homegrown' mb_str_split: "; print_r( $vscharlist ); ?></p><p><?php echo "Using mb_strlen and mb_substr: "; print_r( $vsvscharlist ); ?></p>
</div>
</body>
</html>

