Import XML data

@param   string  $string
@return  array
350545
protected function _fromXml($string, $recursive = false)
	{
		// If it forged with 'xml:ns'
		if ( ! $this->xmlIgnoreNamespaces)
		{
			static $escape_keys = array();

			if ( ! $recursive)
			{
				$escape_keys = array('_xmlns' => 'xmlns');
			}

			if ( ! $recursive and strpos($string, 'xmlns') !== false and preg_match_all('/(\<.+?\>)/s', $string, $matches))
			{
				foreach ($matches[1] as $tag)
				{
					$escaped_tag = $tag;

					strpos($tag, 'xmlns=') !== false and $escaped_tag = str_replace('xmlns=', '_xmlns=', $tag);

					if (preg_match_all('/[\s\<\/]([^\/\s\'"]*?:\S*?)[=\/\>\s]/s', $escaped_tag, $xmlns))
					{
						foreach ($xmlns[1] as $ns)
						{
							$escaped = Arr::search($escape_keys, $ns);
							$escaped or $escape_keys[$escaped = str_replace(':', '_', $ns)] = $ns;
							$string = str_replace($tag, $escaped_tag = str_replace($ns, $escaped, $escaped_tag), $string);
							$tag = $escaped_tag;
						}
					}
				}
			}
		}

		$_arr = is_string($string) ? simplexml_load_string($string, 'SimpleXMLElement', LIBXML_NOCDATA) : $string;
		$arr = array();

		// Convert all objects SimpleXMLElement to array recursively
		foreach ((array)$_arr as $key => $val)
		{
			if ( ! $this->xmlIgnoreNamespaces)
			{
				$key = Arr::get($escape_keys, $key, $key);
			}
			$arr[$key] = (is_array($val) or is_object($val)) ? $this->_fromXml($val, true) : $val;
		}

		return $arr;
	}
596847
public static function stringToArray(?string $string): array {
        $result = [];
        $strLen = \strlen($string);
        if (null === $string) return $result;
        if (1 === $strLen) {
            $result[] = $string;
            return $result;
        }
        for ($i = 0; $i < $strLen; $i++) {
            $result[] = $string[$i];
        }
        return $result;
    }
631899
protected function _parseAttributes($string)
    {
        $result = array();

        if (!empty($string)) {
            $attr   = array();

            preg_match_all('/([\w:-]+)[\s]?=[\s]?"([^"]*)"/i', $string, $attr);

            if (is_array($attr)) {
                $numPairs = count($attr[1]);
                for ($i = 0; $i < $numPairs; $i++) {
                    $result[$attr[1][$i]] = $attr[2][$i];
                }
            }
        }

        return $result;
    }
922329
public static function fromString($string)
    {
        $parts = explode(':', $string, 3);
        Assertion::count($parts, 3, 'NodeRef format must be "vendor:label:id');
        $id = array_pop($parts);
        $qname = SchemaQName::fromString(implode(':', $parts));
        return new self($qname, $id);
    }
379083
public function convertXml($xml)
    {
        try {
            $xml = Xml::build($xml, ['return' => 'domdocument', 'readFile' => false]);
            // We might not get child nodes if there are nested inline entities.
            if ((int)$xml->childNodes->length > 0) {
                return Xml::toArray($xml);
            }

            return [];
        } catch (XmlException $e) {
            return [];
        }
    }
469563
public static function fromXml(string $string) : self
    {
        $xml = new \SimpleXMLElement($string);

        $data = static::xmlToArray($xml);

        return static::decompile($data);
    }
12046
public function parseTags($string)
    {
        foreach ($this->tags as $tag => $code) {
            if (strpos($string, "<{$tag}>") !== false
                || strpos($string, "</{$tag}>") !== false
            ) {
                $string = str_replace("<{$tag}>", $code, $string);
                $string = str_replace("</{$tag}>", $this->tags['default'], $string);
            }
        }

        return $string . $this->tags['default'];
    }
1098695
public static function parse($string)
    {
        if (static::isJSON($string)) {
            $result = static::jsonDecode($string);
        } elseif (static::isXML($string)) {
            $result = static::xmlDecode($string);
        } else {
            throw new \InvalidArgumentException(sprintf('Unable to parse: %s', (string) $string));
        }

        return (array) $result;
    }
282435
protected function parseDocument( $string )
    {
        $document = array();

        // Read document headers
        while ( preg_match( '(\\A(?P<header>[A-Za-z0-9-]+):\s+(?P<value>.*)$)Sm', $string, $match ) )
        {
            $document[$match['header']] = trim( $match['value'] );
            $string = substr( $string, strlen( $match[0] ) + 1 );
        }

        if ( strpos( $document['Content-Type'], 'multipart/mixed' ) === 0 )
        {
            // Rebuild full document
            $body = fopen( 'string://', 'w' );
            foreach ( $document as $key => $value )
            {
                fwrite( $body, "$key: $value\r\n" );
            }
            fwrite( $body, $string );
            fseek( $body, 0 );

            $document['body'] = array();
            $parser = new phpillowToolMultipartParser( $body );
            while ( ( $part = $parser->getDocument() ) !== false )
            {
                $document['body'][] = $part;
            }
        }
        else
        {
            $document['body'] = trim( $string );
        }

        return $document;
    }
593071
public static function stringToArray(string $string): array
    {
        list($from, $to) = explode(self::SEPARATOR, $string);
        $from = empty($from)
            ? self::ZERO
            : (is_numeric($from)
                ? (int) $from
                : $from);

        $to = empty($to)
            ? self::INFINITE
            : (is_numeric($to)
                ? (int) $to
                : $to);

        return [$from, $to];
    }
766331
public function fromString($string, $object = true)
    {
        $data = array();

        if(!empty($string))
        {
            $xml  = simplexml_load_string($string);

            if($xml === false) {
                throw new \DomainException('Cannot parse XML string');
            }

            foreach ($xml->children() as $node) {
                $data[(string) $node['name']] = self::_decodeValue($node);
            }
        }

        return $object ? $this->merge($data) : $data;
    }
112940
public function restoreValueFromXmlString($xmlString)
    {
        $zones = array();
        $attributes = array();
        $layout = null;

        if ($xmlString) {
            $dom = new DOMDocument('1.0', 'utf-8');
            $dom->loadXML($xmlString);
            $root = $dom->documentElement;

            foreach ($root->childNodes as $node) {
                if ($node->nodeType !== XML_ELEMENT_NODE) {
                    continue;
                }

                switch ($node->nodeName) {
                    case 'zone':
                        $zone = $this->restoreZoneFromXml($node);
                        $zones[] = $zone;
                        break;
                    case 'zone_layout':
                        $layout = $node->nodeValue;
                        break;
                    default:
                        $attributes[$node->nodeName] = $node->nodeValue;
                        break;
                }
            }

            if ($root->hasAttributes()) {
                foreach ($root->attributes as $attr) {
                    $attributes[$attr->name] = $attr->value;
                }
            }
        }

        return new Parts\Page(
            array(
                'zones' => $zones,
                'layout' => $layout,
                'attributes' => $attributes,
            )
        );
    }
1194754
public function fromString($string)
        {
            if (empty($string)) {
                return array();
            }
            $this->directory = null;

            set_error_handler(
                function ($error, $message = '', $file = '', $line = 0) {
                    throw new Exception(sprintf(
                        'Error reading INI string: %s',
                        $message
                    ), $error);
                }, E_WARNING
            );
            $ini = parse_ini_string($string, true);
            restore_error_handler();

            return $this->process($ini);
        }
210773
static function unicode_string_to_array( $string )
	{
		$array = array();
		$strlen = mb_strlen($string);
		while ($strlen) {
			$array[] = mb_substr( $string, 0, 1, "UTF-8" );
			$string = mb_substr( $string, 1, $strlen, "UTF-8" );
			$strlen = mb_strlen( $string );
		}
		return $array;
	}
1240915
public static function fromString( $string )
	{
		// Make sure the string does not contain non-hex characters
		$matched = preg_match( "/[^0-9a-fA-F]+/", $string, $matches );
		if ( $matched || strlen( $string ) % 2 != 0 )
		{
			throw XPath2Exception::withErrorCodeAndParams( "FORG0001", Resources::InvalidFormat, array( $string, "xs:hexBinary" ) );
		}

		$binary = hex2bin( $string );
		return new HexBinaryValue( $binary );
	}
487548
public function importFromString($string)
    {
        $this->_paymentMethodsArray = unserialize(urldecode($string));
        $this->_paymentMethodsArrayFiltered = $this->_paymentMethodsArray;
        return $this;
    }
1288348
public static function parse($data)
    {
        $xml = null;
        if ($xml = simplexml_load_string($data)) {
            $xml = (array)$xml;
        }
        return $xml;
    }