PHP код:
function less(string,i,num)
if not string then return end
local bytes = string:len()
if (bytes <= i) then
return string
else
local len, pos = 0, 1
while(pos <= bytes) do
len = len + 1
local c = string:byte(pos)
if (c > 0 and c <= 127) then
pos = pos + 1
elseif (c >= 192 and c <= 223) then
pos = pos + 2
elseif (c >= 224 and c <= 239) then
pos = pos + 3
end
if (len == i) then break end
end
if (len == i and pos <= bytes) then
return string:sub(1, pos - 1)..(num and "..." or "")
else
return string
end
end
end
i = нужное кол-во символов.