My own 'extended' version of nl2br which works in a lot of cases where
the standard nl2br doesnot
@param string $input - the input string to convert
@return string $output - the converted string
423912
public static function nl2br($input)
    {
        $output = str_replace(PHP_EOL, '<br />', $input);
        $output = str_replace("\r\n", '<br />', $output);
        return $output;
    }
346131
public static function toHtmlEntity($input)
    {
        if(is_array($input)){
            foreach ($input as $key=>$value){
                $input[$key]=self::toHtmlEntity($value);
            }
        }else if(is_object($input)){
            $array=get_object_vars($input);
            foreach ($array as $key=>$value){
                $input->$key=self::toHtmlEntity($value);
            }
        }else{
            $input=htmlspecialchars($input);
        }

        return $input;
    }
475626
public function genSalt($input = null)
    {
        if (!$input) {
            $input = $this->_getRandomBytes(6);
        }

        // Hash identifier
        $identifier = $this->_phpBBCompat ? 'H' : 'P';

        // Cost factor
        $costFactor = $this->_itoa64[min($this->_iterationCountLog2 + 5, 30)];

        // Salt string
        $salt = $this->_encode64($input, 6);

        return '$' . $identifier . '$' . $costFactor . $salt;
    }
916428
public static function getConfiguration(string $input) {
    list($oldrev, $newrev, $refname) = explode(' ', $input);
    list(,, $branch) = explode('/', $refname);
    return new ParserVariableConfiguration($oldrev, $newrev, $refname, $branch);
  }
179594
public function encode($input)
    {
        $output = [];

        // Convert the input in UCS-2 to an array of Unicode code points.
        $input = $this->ucs2Decode(mb_convert_encoding($input, "UTF-16"));

        // Cache the length.
        $inputLength = count($input);

        // Initialize the state.
        $n = self::INITIAL_N;
        $delta = 0;
        $bias = self::INITIAL_BIAS;

        // Handle the basic code points.
        for ( $i=0; $i<$inputLength; $i++) {
            $currentValue = $input[$i];
            if ( $currentValue < 0x80) {
                $output[] = chr($currentValue);
            }
        }

        $basicLength = count($output);
        $handledCPCount = $basicLength;

        // `handledCPCount` is the number of code points that have been handled;
        // `basicLength` is the number of basic code points.

        // Finish the basic string with a delimiter unless it's empty.
        if ($basicLength) {
            $output[] = self::DELIMITER;
        }

        // Main encoding loop:
        while ($handledCPCount < $inputLength) {

            // All non-basic code points < n have been handled already. Find the next
            // larger one:
            $m = self::MAX_INT;
            for ( $i=0; $i<$inputLength; $i++) {
                $currentValue = $input[$i];
                if ($currentValue >= $n && $currentValue < $m) {
                    $m = $currentValue;
                }
            }

            // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
            // but guard against overflow.
            $handledCPCountPlusOne = $handledCPCount + 1;
            if ($m - $n > floor((self::MAX_INT - $delta) / $handledCPCountPlusOne)) {
                $this->error('overflow');
            }

            $delta += ($m - $n) * $handledCPCountPlusOne;
            $n = $m;

            for ( $i=0; $i<$inputLength; $i++) {
                $currentValue = $input[$i];
                if ($currentValue < $n && ++$delta > self::MAX_INT) {
                    $this->error('overflow');
                }
                if ($currentValue == $n) {
                    // Represent delta as a generalized variable-$length integer.
                    $q = $delta;
                    for ($k = self::BASE; /* no condition */; $k += self::BASE) {
                        $t = $k <= $bias ? self::T_MIN : ($k >= $bias + self::T_MAX ? self::T_MAX : $k - $bias);
                        if ($q < $t) {
                            break;
                        }
                        $qMinusT = $q - $t;
                        $baseMinusT = self::BASE - $t;
                        $output[] = chr($this->digitToBasic($t + $qMinusT % $baseMinusT, 0));
                        $q = floor($qMinusT / $baseMinusT);
                    }

                    $output[] = chr($this->digitToBasic($q, 0));
                    $bias = $this->adapt($delta, $handledCPCountPlusOne, $handledCPCount == $basicLength);
                    $delta = 0;
                    ++$handledCPCount;
                }
            }

            ++$delta;
            ++$n;

        }
        return join('', $output);
    }
895281
public function convertFromPositive($input)
    {
        $matches = [];

        if (
            !preg_match(
                '
                /^0*(?<carets>\\^*)(?<alpha>[A-Z]*)(?<year>\d+)$/',
                $input,
                $matches
            )
        ) {
            return null;
        }

        if ($matches['alpha'] === '') {
            return $matches['year'];
        }

        if ($matches['carets'] === '') {
            $expectedLength = ord($matches['alpha']) - static::ORD_START + 5;
        } else {
            $len = strlen($matches['carets']);

            $expectedLength = 0;

            for ($i=0; $i < $len; $i++) {
                $expectedLength = $expectedLength * 26;
                $expectedLength += ord($matches['alpha'][$i]) - static::ORD_START;
                $expectedLength++;
            }

            $expectedLength += 30;
        }

        return str_pad($matches['year'], $expectedLength, '0', STR_PAD_RIGHT);
    }
1215454
protected static function convertBase(
        /*# string */ $input,
        /*# string */ $fromBase,
        /*# string */ $toBase
    )/*# : string */ {
        if ($fromBase === $toBase) {
            return $input;
        } elseif ($fromBase === self::BASE10) {
            return static::fromBase10($input, $toBase);
        } elseif ($toBase === self::BASE10) {
            return static::toBase10($input, $fromBase);
        } else {
            return static::fromBase10(static::toBase10($input, $fromBase), $toBase);
        }
    }
1027659
public static function huffmanDecode(string $input) { /* : ?string */
        $lookup = self::$huffmanLookup;
        $len = \strlen($input);
        $out = \str_repeat("\0", $len / 5 * 8 + 1); // max length

        for ($off = $i = 0; $i < $len; $i++) {
            list($lookup, $chr) = $lookup[$input[$i]];

            if ($chr != null) {
                $out[$off++] = $chr;
                if (isset($chr[1])) {
                    $out[$off++] = $chr[1];
                    continue;
                }
                continue;
            }

            if ($chr === "") {
                return null;
            }
        }

        return \substr($out, 0, $off);
    }
761110
public function tokenize(string $input) : TokenStream
    {
        $this->prepare($input);

        // Loop each character
        while ($this->cursor < $this->end) {
            $this->currentChar = $this->input[$this->cursor];

            if (preg_match('@'.Token::REGEX_T_EOL.'@', $this->currentChar)) {
                if ($this->mode !== self::MODE_IDENT) {
                    ++$this->line;
                    $this->lineOffset = $this->cursor + 1;
                }
            }

            switch ($this->mode) {

                case self::MODE_ALL:
                    $this->lexAll();
                    break;
                case self::MODE_INSIDE_TAG:
                    $this->lexInsideTag();
                    break;
                case self::MODE_IDENT:
                    $this->lexIdent();
                    break;
                case self::MODE_VAR:
                    $this->lexVar();
                    break;
                case self::MODE_STRING:
                    $this->lexString();
                    break;
                case self::MODE_NUMBER:
                    $this->lexNumber();
                    break;
                case self::MODE_OP:
                    $this->lexOperator();
                    break;
            }
        }

        return $this->stream;
    }
952170
protected function convertNegativeTo($input)
    {
        $res = $this->convertPositiveTo(substr($input, 1));

        $res = strtr($res, static::POSITIVE_CHARS, static::NEGATIVE_CHARS);

        if (strlen($res) < 5) {
            $res = '/' . $res;
        } elseif ($res[0] !== '!') {
            $res = '*' . $res;
        }

        return $res;
    }
1171445
public function translateFromUtf8($input)
    {
        if ($this->isRunningOnWindows()) {
            $input = iconv('UTF-8', mb_detect_encoding($input), $input);
        }

        return $input;
    }
9947
protected function cleanString($input)
	{
		return htmlentities(
			$input,
			$this->parent->getConfig('htmlentities_flags', ENT_QUOTES),
			$this->parent->getConfig('htmlentities_encoding', 'UTF-8'),
			$this->parent->getConfig('htmlentities_double_encode', false)
		);
	}
219652
protected function unity(string $input): string
    {
        return strtr(mb_convert_kana(strtolower($input), 'c', 'UTF-8'), self::EQUIVALENT);
    }
621240
protected function parseString($input)
    {
        $elements = array();

        $lines = array_filter(explode(PHP_EOL, $input), function($line) {
            return '' != trim($line);
        });

        foreach ($lines as $line) {
            $trimmed = trim($line);
            // if line is not a comment, convert it to a cron
            if (0 !== \strpos($trimmed, '#')) {
                if (preg_match('/^[^\s]+\s?=/', $line)) {
                    $elements[] = Variable::parse($line);
                } else {
                    $elements[] = Job::parse($line);
                }
            }
        }

        return $elements;
    }
112838
public function formatString($input)
    {
        if (is_array($input)) {
            $input = join(', ', $input);
        }
        $output = strip_tags($input);
        $output = str_replace(array("'", "\r", "\n"), array("''", ' ', ' '), $output);
        //$output = "'" . $output . "'";
        return $output;
    }
925133
protected function convertToSnakeCase($input)
    {
        if ($this->convertToSnakeCaseIsDisabled()) {
            return;
        }

        if (is_null($input)) {
            return null;
        } elseif (is_array($input)) {
            return $this->convertArrayToSnakeCase($input);
        }

        return snake_case($input);
    }
153293
private function parse($input)
    {
        $in_comment = false;

        $in_single_quote = false;
        $in_double_quote = false;

        $skip_char = [
            '{', '}', '[', ']', '>',
            '(', ')', ':', ';', ',',
            '+', '=', '~', '"', "'"
        ];

        $input = str_replace(["\r\n", "\r"], "\n", $input);
        $output = '';

        for ($i = 0;$i < strlen($input);$i++) {
            $char = substr($input, $i, 1);
            $pre_input_char = $i != 0 ? substr($input, $i - 1, 1) : null;
            $pre_output_char = substr($output, -1);

            /**
             * Handle comment block and check end tag
             */
            if ($in_comment) {
                if ('*/' === $pre_input_char . $char) {
                    $in_comment = false;
                }

                continue;
            }

            /**
             * Handle quote block and check end tag
             */
            if ($in_single_quote) {
                if ("'" === $char && '\\' !== $pre_output_char) {
                    $in_single_quote = false;
                }

                $output .= $char;
                continue;
            }

            if ($in_double_quote) {
                if ('"' === $char && '\\' !== $pre_output_char) {
                    $in_double_quote = false;
                }

                $output .= $char;
                continue;
            }

            /**
             * Check start tag of comment block
             */
            if ('/*' === $pre_output_char . $char) {
                $in_comment = true;

                $output = substr($output, 0, strlen($output) - 1);
                continue;
            }

            /**
             * Check start tag of quote block
             */
            if ("'" === $char) {
                if (' ' === $pre_output_char) {
                    $output = substr($output, 0, strlen($output) - 1);
                }

                $in_single_quote = true;

                $output .= $char;
                continue;
            }

            if ('"' === $char) {
                if (' ' === $pre_output_char) {
                    $output = substr($output, 0, strlen($output) - 1);
                }

                $in_double_quote = true;

                $output .= $char;
                continue;
            }

            /**
             * Handle normal block
             */
            if ("\n" === $char || "\t" === $char) {
                continue;
            }

            if (' ' === $char && ' ' === $pre_output_char) {
                continue;
            }

            if (' ' === $char && in_array($pre_output_char, $skip_char)) {
                continue;
            }

            if (' ' === $pre_output_char && in_array($char, $skip_char)) {
                $output = substr($output, 0, strlen($output) - 1);
            }

            if ('(' === $char && 'and' === substr($output, -3)) {
                $char = ' (';
            }

            $output .= $char;
        }

        return trim($output);
    }