Example #1
0
function str_cut($str, $maxlen, $type)
{
    $str = str_trans_rev($str);
    $len = strlen($str);
    if ($len <= $maxlen) {
        return str_tag_off(str_trans($str));
    }
    $return_str = "";
    for ($i = 0; $i < $maxlen - 1; $i++) {
        if (ord(substr($str, $i, 1)) < 128) {
            $return_str .= substr($str, $i, 1);
        } else {
            $return_str .= substr($str, $i, 2);
            $i++;
        }
    }
    $str = str_tag_off(str_trans($str));
    $return_str = str_tag_off(str_trans($return_str));
    if ($type) {
        return "<span title=\"{$str}\">{$return_str}..</span>";
    } else {
        return $return_str . "..";
    }
}
Example #2
0
<?php

if (!isset($_GET['submit'])) {
    echo "<form action ='task01.php' method='get'>";
    echo '<input type="text" name="str">';
    echo '<input type="text" name="sym">';
    echo '<input type="submit" name="submit" value="submit">';
    echo "</form>";
} else {
    $str_user = $_GET['str'];
    $sym_user = $_GET['sym'];
    function str_trans($var1, $var2)
    {
        $res_str = explode(' ', $var1);
        $count = count($res_str);
        echo "<ul>";
        for ($i = 0; $i < $count; $i++) {
            $res_str[$i] = str_split($res_str[$i]);
            $current_count = count($res_str[$i]);
            for ($j = 1; $j < $current_count; $j++) {
                $res_str[$i][$j] = $var2;
            }
            $res_str[$i] = implode(" ", $res_str[$i]);
            echo "<li>" . $res_str[$i] . "</li>";
        }
        echo "</ul>";
    }
}
str_trans($str_user, $sym_user);