Adjust xml string to the proper format

@param string $string - XML string document
@return string - Return the string converted
@throws \ByJG\Util\Exception\XmlUtilException
428564
public static function fixXmlHeader($string)
    {
        $string = XmlUtil::removeBom($string);

        if (strpos($string, "<?xml") !== false) {
            $xmltagend = strpos($string, "?>");
            if ($xmltagend !== false) {
                $xmltagend += 2;
                $xmlheader = substr($string, 0, $xmltagend);

                if ($xmlheader == "<?xml?>") {
                    $xmlheader = "<?xml ?>";
                }
            } else {
                throw new XmlUtilException("XML header bad formatted.", 251);
            }

            // Complete header elements
            $count = 0;
            $xmlheader = preg_replace(
                "/version=([\"'][\w\d\-\.]+[\"'])/",
                "version=\"".self::XML_VERSION."\"",
                $xmlheader,
                1,
                $count
            );
            if ($count == 0) {
                $xmlheader = substr($xmlheader, 0, 6)."version=\"".self::XML_VERSION."\" ".substr($xmlheader, 6);
            }
            $count = 0;
            $xmlheader = preg_replace(
                "/encoding=([\"'][\w\d\-\.]+[\"'])/",
                "encoding=\"".self::XML_ENCODING."\"",
                $xmlheader,
                1,
                $count
            );
            if ($count == 0) {
                $xmlheader = substr($xmlheader, 0, 6)."encoding=\"".self::XML_ENCODING."\" ".substr($xmlheader, 6);
            }

            // Fix header position (first version, after encoding)
            $xmlheader = preg_replace(
                "/<\?([\w\W]*)\s+(encoding=([\"'][\w\d\-\.]+[\"']))\s+(version=([\"'][\w\d\-\.]+[\"']))\s*\?>/",
                "<?\\1 \\4 \\2?>",
                $xmlheader,
                1,
                $count
            );

            return $xmlheader.substr($string, $xmltagend);
        } else {
            $xmlheader = '<?xml version="'.self::XML_VERSION.'" encoding="'.self::XML_ENCODING.'"?>';
            return $xmlheader.$string;
        }
    }
236724
public function html($string)
    {
        if (!$string) {
            return $string;
        }

        $result = htmlspecialchars($string, $this->htmlSpecialCharsFlags, $this->encoding);
        return $result;
    }
966845
public static function stringToValue($string)
	{
		if($string == '')
		{
			return $string;
		}
		if(is_float($string))
		{
			return (float) $string;
		}
		if(is_int($string))
		{
			return (int) $string;
		}
		if(strtolower($string) == 'true')
		{
			return true;
		}
		if(strtolower($string) == 'false')
		{
			return false;
		}
		if(strtolower($string) == 'null')
		{
			return NULL;
		}
		
		return $string;
	}
402539
public static function fromString(string $string): self
    {
        if (1 !== \preg_match('/^( *|\t+)$/', $string)) {
            throw Exception\InvalidIndentStringException::fromString($string);
        }

        return new self($string);
    }
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;
    }
623502
public function parseHtml( $string )
	{
		$this->document = new DOMDocument();
		ob_start();
		$this->document->loadHTML( $string );
		$content	= ob_get_clean();
		if( $content )
			$this->errors	= $content;
	}
1339199
public function parseString($string)
    {
        $string = (string) $string;
        $string = preg_replace_callback("/\\$\{(.*?)\}/",
            function ($k) {
                return $this->get($k[1]);
            }, $string);

        return $string;
    }
719838
final public static function handlifyString($string)
    {
        $string = preg_replace('/\W+/', '_', $string);
        $string = preg_replace('/([A-Z])/', '_$1', $string);
        $string = strtolower($string);
        $string = preg_replace('/_+/', '_', trim($string, '_'));

        return $string;
    }
1108838
public static function fromString($string)
	{
		$fg      = '';
		$bg      = '';
		$options = array();

		$parts = explode(';', $string);

		foreach ($parts as $part)
		{
			$subParts = explode('=', $part);

			if (\count($subParts) < 2)
			{
				continue;
			}

			switch ($subParts[0])
			{
				case 'fg':
					$fg = $subParts[1];

					break;

				case 'bg':
					$bg = $subParts[1];

					break;

				case 'options':
					$options = explode(',', $subParts[1]);

					break;

				default:
					throw new \RuntimeException('Invalid option');

					break;
			}
		}

		return new self($fg, $bg, $options);
	}
767735
protected function escape(string $string): string
	{
		if($this->formatter !== null)
		{
			return $this->formatter->escape($string);
		}

		return $string;
	}
1075240
public function apply(string $string) : string
    {
        return str_replace($this->search, $this->replace, $string);
    }
69112
function _convertString($string)
	{
		// chop away beggining and ending quotes
		$string = substr($string, 1, strlen($string) - 2);
		if (strlen($string) > 255) {
			throw new PHPExcel_Writer_Exception("String is too long");
		}

		return pack('C', $this->ptg['ptgStr']) . PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($string);
	}
963900
public function tokenize($string)
    {
        $line     = 1;
        $position = 1;
        $tokens   = array();

        while (strlen($string)) {
            foreach ($this->expressions as $rule) {
                if (!preg_match($rule['match'], $string, $match)) {
                    continue;
                }

                // Remove matched string from input
                $string = substr($string, strlen($match[0]));

                // Update position in file
                $line += substr_count($match[0], "\n");
                if (($pos = strrpos($match[0], "\n")) !== false) {
                    $position  = strrpos($match[0], "\n") + 1;
                } else {
                    $position += strlen($match[0]);
                }

                // Skip irrelevant rules
                if (in_array($rule['type'], $this->ignoreTokens)) {
                    continue 2;
                }

                // Add all other rules including their match to the token array
                $match = $this->removeNumericKeys($match);
                $tokens[] = new Token($rule['type'], $line, $position, $match);
                continue 2;
            }

            throw new \RuntimeException(
                "Could not parse string: '" . substr($string, 0, 20) . "' in line $line at position $position."
            );
        }

        $tokens[] = new Token(self::T_EOF, $line, $position, null);
        return $tokens;
    }
1142004
public static function clean($string): string
    {
        $string = trim($string);
        $string = htmlspecialchars($string);
        return $string;
    }
369935
public function setString($string = '')
    {
        try {
            Assert::string($string);
        } catch (InvalidArgumentException $e) {
            $this->string = '';
        }

        $this->string = $string;

        return $this;
    }
548936
public function xml_escape($string) {
        if (!empty($string) && htmlspecialchars($string) != $string) {
            // If the string contains something that looks like the end
            // of a CDATA section, then we need to avoid errors by splitting
            // the string between two CDATA sections.
            $string = str_replace(']]>', ']]]]><![CDATA[>', $string);
            return "<![CDATA[{$string}]]>";
        } else {
            return $string;
        }
    }
1069501
public function fromString($xmlString)
    {
        $xml = $this->createDomDocument();
        $xml->loadXml($xmlString);

        return new Document($xml);
    }