Wordwrap in UTF-8 supports, return as array

@param string $string
@param int    $width

@return array
168236
public function wordwrapArray($string, $width)
		{
			if (($len = mb_strlen($string, 'UTF-8')) <= $width) {
				return [$string];
			}
			$return     = [];
			$last_space = FALSE;
			$i          = 0;
			do {
				if (mb_substr($string, $i, 1, 'UTF-8') == ' ') {
					$last_space = $i;
				}
				if ($i > $width) {
					$last_space = ($last_space == 0) ? $width : $last_space;
					$return[]   = trim(mb_substr($string, 0, $last_space, 'UTF-8'));
					$string     = mb_substr($string, $last_space, $len, 'UTF-8');
					$len        = mb_strlen($string, 'UTF-8');
					$i          = 0;
				}
				$i++;
			} while ($i < $len);
			$return[] = trim($string);

			return $return;
		}
800999
public static function wrap($comment, $format, $width = 80)
    {
        $result = array();
        $width = $width - self::getWidth($format);
        // collect lines
        $lines = array();
        foreach (explode("\n", $comment) as $line) {
            foreach (explode("\n", wordwrap($line, $width, "\n")) as $sline) {
                $lines[] = $sline;
            }
        }
        // write lines
        $no = 0;
        $count = count($lines);
        foreach ($lines as $line) {
            $no++;
            self::getLine($no, $count, $format, $line, $result);
        }

        return $result;
    }
921646
protected function strTokenWrapper($string)
    {
        $token = strtok($string, $this->tokenExpression);

        $tokens = array();
        while ($token !== false) {
            // avoid tokenizing white spaces
            if(!empty(trim($token))) { 
                $tokens[] = $token;
            }
            $token = strtok($this->tokenExpression);        
        }
        return $tokens;
    }
1028685
public static function abbreviate($string, $maxWidth)
    {
        if (mb_strlen($string) > $maxWidth) {
            return mb_substr($string, 0, $maxWidth) . '...';
        }
        return $string;
    }
716344
@Deprecated
	public static String wordWrap(String string, int width) {
		// Leave room for two word wrap characters every width / 2 characters, on average.
		int inputLength = string.length();
		int estimatedLines = 2 * inputLength / width;
		int initialLength = inputLength + estimatedLines * 2;
		try {
			StringBuilder buffer = new StringBuilder(initialLength);
			wordWrap(string, width, buffer);
			return buffer.toString();
		} catch(IOException e) {
			throw new AssertionError("Should not get IOException from StringBuilder", e);
		}
	}
183094
private static function mbStringToArray($string)
    {
        $stop   = mb_strlen($string, 'utf-8');
        $result = array();

        for ($idx = 0; $idx < $stop; $idx++) {
            $result[] = mb_substr($string, $idx, 1, 'utf-8');
        }

        return $result;
    }
75932
public static function rtrimWord($string, $word)
    {
        $end = mb_substr($string, 0-mb_strlen($word));
        if ($end != $word) {
            return $string;
        }
        return mb_substr($string, 0, mb_strlen($string)-mb_strlen($word));
    }
198158
public static function convertToUtf8(string $string): string
    {
        // If it's already a UTF8 string, just clean and return it
        if (static::isUtf8($string)) {
            return HtmlPurifier::cleanUtf8($string);
        }

        // Otherwise set HTMLPurifier to the actual string encoding
        $config = \HTMLPurifier_Config::createDefault();
        $config->set('Core.Encoding', static::encoding($string));

        // Clean it
        $string = HtmlPurifier::cleanUtf8($string);

        // Convert it to UTF8 if possible
        if (function_exists('iconv') && \HTMLPurifier_Encoder::testIconvTruncateBug() === \HTMLPurifier_Encoder::ICONV_OK) {
            $string = HtmlPurifier::convertToUtf8($string, $config);
        } else {
            $encoding = static::encoding($string);
            $string = mb_convert_encoding($string, 'utf-8', $encoding);
        }

        return $string;
    }
1333001
public static function html2rgb( $string )
	{
		sscanf( $string, "%2X%2X%2X", $r, $g, $b );
		return array( $r, $g, $b );
	}
1070141
function smart_wordwrap($string, $width = 75, $break = "\n")
    {
        // split on problem words over the line length
        $pattern = sprintf('/([^ ]{%d,})/', $width);
        $output  = '';
        $words   = preg_split($pattern, $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);

        foreach ($words as $word) {
            if (false !== strpos($word, ' ')) {
                // normal behaviour, rebuild the string
                $output .= $word;
            } else {
                // work out how many characters would be on the current line
                $wrapped = explode($break, wordwrap($output, $width, $break));
                $count   = $width - (strlen(end($wrapped)) % $width);

                // fill the current line and add a break
                $output .= substr($word, 0, $count) . $break;

                // wrap any remaining characters from the problem word
                $output .= wordwrap(substr($word, $count), $width, $break, true);
            }
        }

        // wrap the final output
        return wordwrap($output, $width, $break);
    }
1316436
function _strunrep( $string ) {
    $string = str_replace( '\\\\', '\\',     $string);
    $string = str_replace( '\,',   ',',      $string);
    $string = str_replace( '\;',   ';',      $string);
//    $string = str_replace( '\n',  $this->nl, $string); // ??
    return $string;
  }
438425
public function nl2p($string)
    {
        // replace lineFeed with <br /> tag
        $lineFeed = chr(10);
        $value = preg_replace('#'.$lineFeed.'#', '<br />', $string);

        // replace double <br /> tags with </p><p> tags
        $pattern = '#<br />([ ]*)<br />#';
        $replacement = '</p><p>';
        $result = preg_replace($pattern, $replacement, $value);

        return $result;
    }
304810
public static byte[] utf8Encode(CharSequence string) {
		try {
			ByteBuffer bytes = UTF8.newEncoder().encode(CharBuffer.wrap(string));
			byte[] bytesCopy = new byte[bytes.limit()];
			System.arraycopy(bytes.array(), 0, bytesCopy, 0, bytes.limit());
			return bytesCopy;
		}
		catch (CharacterCodingException e) {
			throw new RuntimeException(e);
		}
	}
359134
static function _utf8_wordwrap2($str, $width = 75, $break = "\n", $cut = false)
	{
		if(!$cut)
			$regexp = '#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.$width.',}\b#U';
		else
			$regexp = '#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.$width.'}#';

		if(function_exists('mb_strlen'))
			$str_len = mb_strlen($str,'UTF-8');
		else
			$str_len = preg_match_all('/[\x00-\x7F\xC0-\xFD]/', $str, $var_empty);

		$while_what = ceil($str_len / $width);
		$i = 1;
		$return = '';

		while ($i < $while_what)
		{
			preg_match($regexp, $str, $matches);
//			var_dump($regexp, $str, $matches);
			$string = $matches[0];
			$return .= $string.$break;
			$str = substr($str, strlen($string));
			$i++;
		}

		return $return.$str;
	}
44322
public function textWrap(string $str, float $width): string
    {
        // Calculate the line width
        $lw = (int) ($width / ($this->getCurrentStyleHeight() / 2));
        // Wordwrap each line
        $lines = explode("\n", $str);
        // Line Feed counter
        $lfct     = count($lines);
        $wraptext = '';
        foreach ($lines as $line) {
            $wtext = FunctionsRtl::utf8WordWrap($line, $lw, "\n", true);
            $wraptext .= $wtext;
            // Add a new line as long as it’s not the last line
            if ($lfct > 1) {
                $wraptext .= "\n";
            }
            $lfct--;
        }

        return $wraptext;
    }
455045
protected static function convertDoubleWidth( $string ) {
		static $full = null;
		static $half = null;

		if ( $full === null ) {
			$fullWidth = "０１２３４５６７８９ＡＢＣＤＥＦＧＨＩＪＫＬＭＮＯＰＱＲＳＴＵＶＷＸＹＺａｂｃｄｅｆｇｈｉｊｋｌｍｎｏｐｑｒｓｔｕｖｗｘｙｚ";
			$halfWidth = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
			$full = str_split( $fullWidth, 3 );
			$half = str_split( $halfWidth );
		}

		$string = str_replace( $full, $half, $string );
		return $string;
	}
262432
protected function levenshteinUtf8($string1, $string2)
    {
        $charMap = array();
        $string1 = $this->utf8ToExtendedAscii($string1, $charMap);
        $string2 = $this->utf8ToExtendedAscii($string2, $charMap);

        return levenshtein($string1, $string2);
    }