Get max bytes needed per char.

@param string $string

@return int
511333
public static function maxCharWidth($string)
    {
        $chars = preg_split('//u', $string, null, PREG_SPLIT_NO_EMPTY);

        if (!$chars) {
            return 0;
        }

        $sizes = array_map('strlen', $chars);

        return max($sizes);
    }
989087
protected function convertString($string)
    {
        $charset = strtolower($this->getCharset());
        if (!in_array($charset, ['utf-8', 'iso-8859-1', 'iso-8859-15', ''])) {
            return mb_convert_encoding($string, $charset, 'utf-8');
        }

        return $string;
    }
310392
public function write($string)
    {
        $this->content = substr_replace($this->content, $string, $this->position, 0);
        $len = strlen($string);
        $this->position += $len;
        return $len;
    }
499748
protected function getChecksum($string)
    {
        $checksum = '';
        foreach (str_split(strrev($string)) as $i => $d) {
            $checksum .= ($i % 2 === 0) ? ($d * 2) : $d;
        }
        return (10 - array_sum(str_split($checksum)) % 10) % 10;
    }
702343
public static function toBytes ($string)
		{
			$value = null;
			$string = strtoupper($string);

			preg_match('/(\d+)\s?([KMGT]?)/', $string, $match);

			if (isset($match[ 2 ]))
			{
				$digit = (int) $match[ 1 ];
				switch ($match[ 2 ])
				{
					case 'K':
						$value = $digit << 10;
						break;

					case 'M':
						$value = $digit << 20;
						break;

					case 'G':
						$value = $digit << 30;
						break;

					case 'T':
						$value = $digit << 40;
						break;

					default:
						$value = $digit;
						break;
				}
			}

			return $value;
		}
455173
public function getNumberFromString( $string )
    {
        preg_match( '/(?P<digit>\d+)/', $string, $result );
        Assertion::assertNotEmpty( $result['digit'], "Expected to find a number in '$string' found none" );
        return (int)$result['digit'];
    }
1178567
public function compareToIgnoreCase($string): int
    {
        Assert::typeOf(['string', __CLASS__], $string);

        return strcasecmp($this->data, (string) $string) <=> 0;
    }
737717
static public function isUTF8($string)
    {
        for ($idx = 0, $strlen = strlen($string); $idx < $strlen; $idx++) {
            $byte = ord($string[$idx]);

            if ($byte & 0x80) {
                if (($byte & 0xE0) == 0xC0) {
                    $bytes_remaining = 1;
                } else if (($byte & 0xF0) == 0xE0) {
                    $bytes_remaining = 2;
                } else if (($byte & 0xF8) == 0xF0) {
                    $bytes_remaining = 3;
                } else {
                    return false;
                }

                if ($idx + $bytes_remaining >= $strlen) {
                    return false;
                }

                while ($bytes_remaining--) {
                    if ((ord($string[++$idx]) & 0xC0) != 0x80) {
                        return false;
                    }
                }
            }
        }

        return true;
    }
371153
public function getValue($string)
    {
        // now just drop the msb and reorder it + parse it in own string
        $valuestring = '';
        $string_length = strlen($string);

        $i = 1;

        while ($string_length > $i) {
            // unset msb string and reorder it
            $valuestring = substr($string, $i, 7) . $valuestring;
            $i += 8;
        }

        // now interprete it
        return bindec($valuestring);
    }
432502
private function convertToUTF8($string)
    {
        $encoding = mb_detect_encoding($string, mb_detect_order(), false);

        if ($encoding == "UTF-8") {
            $string = mb_convert_encoding($string, 'UTF-8', 'UTF-8');
        }

        $out = iconv(mb_detect_encoding($string, mb_detect_order(), false), "UTF-8//IGNORE", $string);
        return $out;
    }
553531
public static byte[] getBytes(String string) {
    byte[] result = new byte[utf8Length(string)];
    try {                                         // avoid sync'd allocations
      writeChars(result, string, 0, string.length());
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    return result;
  }
901810
public static function cleanupString($string)
    {
        $string = trim($string);
        $string = str_replace(array("\n", "\r", "\0"), '', $string);

        $limit = Config::getInstance()->Tracker['page_maximum_length'];
        $clean = substr($string, 0, $limit);
        return $clean;
    }
262617
protected static function strLen($string){
    $encoding = function_exists('mb_detect_encoding') ? mb_detect_encoding($string) : false;
    return $encoding ? mb_strlen($string, $encoding) : strlen($string);
  }
574705
public function lastIndexOf($string, int $offset = 0): int
    {
        Assert::typeOf(['string', __CLASS__], $string);
        $pos = mb_strrpos($this->data, (string) $string, $offset, $this->encoding);

        return $pos > -1 ? $pos : -1;
    }
1231460
private function stringToNum(string $string) : BigNumber
    {
        $number = new BigNumber(0);
        foreach (str_split(strrev($string)) as $char) {
            $number->multiply($this->alphabetLength)->add(array_search($char, $this->alphabet, false));
        }

        return $number;
    }
739352
public static function ucFirst($string)
    {
        return self::strToUpper(mb_substr($string, 0, 1, 'UTF-8'))
        . self::strToLower(mb_substr($string, 1, null, 'UTF-8'));
    }
579911
private function limitBytes($bytes)
    {
        if ($bytes === null) {
            return $this->content;
        } elseif (intval($bytes) < (self::BYTE_LIMIT * 0.046875)) {
            // less than 24 kilobytes (512 kilobytes * 0.046875)
            throw new \InvalidArgumentException('Byte limit is set dangerously low! Default value=' . self::BYTE_LIMIT);
        }
        return $this->content = mb_strcut($this->content, 0, intval($bytes));
    }