Skip to content

Instantly share code, notes, and snippets.

@damiann
Created October 18, 2014 00:41
Show Gist options
  • Save damiann/58d64d86345af3cb737f to your computer and use it in GitHub Desktop.
Save damiann/58d64d86345af3cb737f to your computer and use it in GitHub Desktop.
<?php
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
function get_fname($string, $sub) {
$bad = array("<", ">", ":", '"', "/", "\\", "|", "?", "*");
$name = str_replace($bad, "_", $string);
echo strlen(utf8_decode($string));
if (strlen($string) > $sub) {
$name = mb_substr($string,0,$sub, "utf-8");
}
return $name;
}
$test_string = "gëén";
$sub_arr = array(1,2,3);
foreach ($sub_arr as $sub) {
echo get_fname($test_string, $sub);
echo "<br />";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment