Substr in UTF-8

<?php
function mySubstr($str,$num){
  return mb_substr($str,0,$num,'utf8');
}

echo esc_html(mySubstr(get_the_title(),30));