API16

JUtility/parseAttributes

From Joomla! Documentation

< API16:JUtility
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Method to extract key/value pairs out of a string with xml style attributes



Syntax[edit]

static parseAttributes($string)
Parameter Name Default Value Description
$string $string String containing xml style attributes

Returns[edit]

array Key/Value pairs for the attributes

Defined in[edit]

libraries/joomla/utilities/utility.php

Importing[edit]

jimport( 'joomla.utilities.utility' );

Source Body[edit]

public static function parseAttributes($string)
{
        // Initialise variables.
        $attr           = array();
        $retarray       = array();

        // Lets grab all the key/value pairs using a regular expression
        preg_match_all('/([\w:-]+)[\s]?=[\s]?"([^"]*)"/i', $string, $attr);

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



Examples[edit]

Code Examples[edit]