function utf8_strtrunc($str, $len) {
		$i = $len - 1;
		if (ord($str{$i}) & 0x80) { // part of a multibyte sequence
			for (; $i > 0 && !(ord($str{$i}) & 0x40); $i--) {
				// find the first byte
				;
			}
			if ($i <= 0) {
				return '';
			} // sanity check
			for ($bc = 0, $mbs = ord($str{$i}); $mbs & 0x80; $mbs = $mbs << 1) {
				// calculate number of bytes
				$bc++;
			}
			if ($bc + $i > $len) {
				return substr($str, 0, $i);
			}
			// fallthru: multibyte char fits into length
		}
		return substr($str, 0, $len);
	}