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.

Revisions

  1. damiann renamed this gist Oct 18, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. damiann created this gist Oct 18, 2014.
    22 changes: 22 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    <?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 />";
    }

    ?>