Actions

API16

JUtility/parseAttributes

From Joomla! Documentation

< API16:JUtility
Revision as of 16:56, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

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

[Edit Descripton]

Description:JUtility/parseAttributes

Syntax

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

Returns

array Key/Value pairs for the attributes

Defined in

libraries/joomla/utilities/utility.php

Importing

jimport( 'joomla.utilities.utility' );

Source Body

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;
}

[Edit See Also] SeeAlso:JUtility/parseAttributes

Examples

<CodeExamplesForm />