function substr_u($text, $sub_len)
{
$rv = "";
$cut_len = 0;
$len = strlen($text);
$pos = 0;
while($cut_len < $sub_len)
{
switch($text[$pos])
{
case "&":
$tmp = substr($text, $pos);
if (($elem = strpos($tmp, ";")) == false)
{
$rv .= "&";
}
else
{
$rv .= substr($tmp, 0, $elem + 1);
$pos += $elem;
}
break;
default:
$rv .= $text[$pos];
break;
}
$pos++;
$cut_len++;
}
return $rv;
}