Removes the BOM from unicode string {@link http://unicode.org/faq/utf_bom.html}

@param string $str input string
@return string
767707
public static function trim_utf8_bom($str) {
        $bom = "\xef\xbb\xbf";
        if (strpos($str, $bom) === 0) {
            return substr($str, strlen($bom));
        }
        return $str;
    }
357046
private function filterQueryAndFragment($str)
    {
        return preg_replace_callback(
            '/(?:[^' . self::$charUnreserved . self::$charSubDelims . '%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/',
            function ($match) { return rawurlencode($match[0]); },
            $str
        );
    }
735707
public static function strip_html($str) {
        $str = preg_replace('/^\s*(.*?)\s*$/im', '$1', $str);
        $str = preg_replace('/^\/\/(.*?)$/im', '', $str);
        $str = preg_replace('/\r|\n/i', ' ', $str);
        $str = preg_replace('/\>\s*(.*?)\s*\</im', '>$1<', $str);
        $str = preg_replace('/\s{2,}/i', ' ', $str);
        return $str;
    }
680854
public static function strlen($str) {
    if (is_array($str))
      return false;

    if (function_exists('mb_strlen'))
      return mb_strlen($str, 'UTF-8');

    return strlen($str);
  }
1088735
public function withoutBOM($string)
    {
        if ($bom = $this->findBOM($string)) {
            return substr($string, strlen($bom));
        }
        return $string;
    }
273290
public function convertToUtf8($str) {
        if (mb_detect_encoding($str, "UTF-8, ISO-8859-1, GBK")!="UTF-8") {
            $str = utf8_encode($str);
        }
        $str = iconv('UTF-8', 'UTF-8//IGNORE', $str);
        return $str;
    }
1072216
public function toBin(string $str):string {
		$this->checkCharacterSet($str);

		// Convert the base32 string back to a binary string
		$str = array_map(function($chr){
			return sprintf('%08b', strpos($this->charset, $chr));
		}, str_split($str));

		// Remove the extra 0's we added
		$str = preg_replace('/000(.{5})/', '$1', implode('', $str));

		// Unpad if nessicary
		$length = strlen($str);
		$rbits = $length&7;

		if($rbits > 0){
			$str = substr($str, 0, $length-$rbits);
		}

		return $str;
	}
186785
public function clean_string($str)
    {
        if ($this->is_ascii($str) === FALSE) {
            if (MB_ENABLED) {
                $str = mb_convert_encoding($str, 'UTF-8', 'UTF-8');
            } elseif (ICONV_ENABLED) {
                $str = @iconv('UTF-8', 'UTF-8//IGNORE', $str);
            }
        }

        return $str;
    }
352850
public static function cleanTextarea($str)
  {
    $str = str_replace('&nbsp;', ' ', $str);
    $str = preg_replace("/[\r\n]{2,}/", "\n\n", $str);
    $str = preg_replace("/<br([^>]*)>/", "\n", $str);
    
    if ( !preg_match("/<(p|table|figure|div|h[1-6])>.+<\/$1>/", $str) ){
      $str = '<p>'.$str.'</p>';
    }
    $str = preg_replace("/\n\n/", "</p> <p>", $str);
    $str = trim($str);
    $str = preg_replace("/<p>\s*<\/p>/", "", $str);
    $str = preg_replace("/\n/", "<br />", $str);
    $str = trim($str);
    
    return $str;
  }
775488
protected function unserialize($str)
    {
        $str  = str_replace("'", '"', $str);
        $data = @unserialize($str);
        if ($str === 'b:0;' || $data !== false) {
            return $data;
        }
        return false;
    }
979075
protected function _removeBlobWhenNonempty(&$str)
    {
        if ($str &&
            ($str[0] === '[') &&
            (($i = $this->_removeBlob($str, 0)) !== false) &&
            ($i !== strlen($str))) {
            $str = substr($str, $i);
            return true;
        }

        return false;
    }
1187029
public static function restoreLineBreaks($str)
    {
        if (isset($str) and strlen($str) !== 0) {
            $result = str_replace(PHP_EOL, "\n\r<br />\n\r", $str);

            return $result;
        } else {
            return false;
        }
    }
1139605
function UTF8toSubset($str)
	{
		$ret = '<';
		// $str = preg_replace('/'.preg_quote($this->aliasNbPg,'/').'/', chr(7), $str );	// mPDF 6 deleted
		// $str = preg_replace('/'.preg_quote($this->aliasNbPgGp,'/').'/', chr(8), $str );	// mPDF 6 deleted
		$unicode = $this->UTF8StringToArray($str);
		$orig_fid = $this->CurrentFont['subsetfontids'][0];
		$last_fid = $this->CurrentFont['subsetfontids'][0];
		foreach ($unicode as $c) {
			/* 	// mPDF 6 deleted
			  if ($c == 7 || $c == 8) {
			  if ($orig_fid != $last_fid) {
			  $ret .= '> Tj /F'.$orig_fid.' '.$this->FontSizePt.' Tf <';
			  $last_fid = $orig_fid;
			  }
			  if ($c == 7) { $ret .= $this->aliasNbPgHex; }
			  else { $ret .= $this->aliasNbPgGpHex; }
			  continue;
			  }
			 */
			if (!$this->_charDefined($this->CurrentFont['cw'], $c)) {
				$c = 0;
			} // mPDF 6
			for ($i = 0; $i < 99; $i++) {
				// return c as decimal char
				$init = array_search($c, $this->CurrentFont['subsets'][$i]);
				if ($init !== false) {
					if ($this->CurrentFont['subsetfontids'][$i] != $last_fid) {
						$ret .= '> Tj /F' . $this->CurrentFont['subsetfontids'][$i] . ' ' . $this->FontSizePt . ' Tf <';
						$last_fid = $this->CurrentFont['subsetfontids'][$i];
					}
					$ret .= sprintf("%02s", strtoupper(dechex($init)));
					break;
				} // TrueType embedded SUBSETS
				elseif (count($this->CurrentFont['subsets'][$i]) < 255) {
					$n = count($this->CurrentFont['subsets'][$i]);
					$this->CurrentFont['subsets'][$i][$n] = $c;
					if ($this->CurrentFont['subsetfontids'][$i] != $last_fid) {
						$ret .= '> Tj /F' . $this->CurrentFont['subsetfontids'][$i] . ' ' . $this->FontSizePt . ' Tf <';
						$last_fid = $this->CurrentFont['subsetfontids'][$i];
					}
					$ret .= sprintf("%02s", strtoupper(dechex($n)));
					break;
				} elseif (!isset($this->CurrentFont['subsets'][($i + 1)])) {
					// TrueType embedded SUBSETS
					$this->CurrentFont['subsets'][($i + 1)] = [0 => 0];
					$new_fid = count($this->fonts) + $this->extraFontSubsets + 1;
					$this->CurrentFont['subsetfontids'][($i + 1)] = $new_fid;
					$this->extraFontSubsets++;
				}
			}
		}
		$ret .= '>';
		if ($last_fid != $orig_fid) {
			$ret .= ' Tj /F' . $orig_fid . ' ' . $this->FontSizePt . ' Tf <> ';
		}
		return $ret;
	}
649525
public static function removeUnsafeChars($str) {
		static $blacklist = '/[!\"?():\']/';
		static $whitelist = '/[^a-zA-Z0-9-_.]/';
		$validStr = preg_replace(array($blacklist, $whitelist), array('', '-'), $str);
		return $validStr;
	}
1303472
protected function sanitizeComponent($str)
    {
        if (is_null($str)) {
            return $str;
        }
        $str = filter_var((string) $str, FILTER_UNSAFE_RAW, array('flags' => FILTER_FLAG_STRIP_LOW));
        $str = trim($str);

        return $str;
    }
116440
function filterText($text, $bom = true, $convert_encoding = true)
    {
        if (!$this->numFonts) {
            $this->selectFont($this->defaultFont);
        }

        if ($convert_encoding) {
            $cf = $this->currentFont;
            if (isset($this->fonts[$cf]) && $this->fonts[$cf]['isUnicode']) {
                $text = $this->utf8toUtf16BE($text, $bom);
            } else {
                //$text = html_entity_decode($text, ENT_QUOTES);
                $text = mb_convert_encoding($text, self::$targetEncoding, 'UTF-8');
            }
        } else if ($bom) {
            $text = $this->utf8toUtf16BE($text, $bom);
        }

        // the chr(13) substitution fixes a bug seen in TCPDF (bug #1421290)
        return strtr($text, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
    }
635070
public static function decode(String $str) : String
    {
        return preg_replace
        (
            array_keys(self::$scriptTagCharsDecode), 
            array_values(self::$scriptTagCharsDecode), 
            $str
        );
    }