Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
utility.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Utilities
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * JUtility is a utility functions class
14  *
15  * @package Joomla.Platform
16  * @subpackage Utilities
17  * @since 11.1
18  */
19 class JUtility
20 {
21  /**
22  * Method to extract key/value pairs out of a string with XML style attributes
23  *
24  * @param string $string String containing XML style attributes
25  *
26  * @return array Key/Value pairs for the attributes
27  *
28  * @since 11.1
29  */
30  public static function parseAttributes($string)
31  {
32  $attr = array();
33  $retarray = array();
34 
35  // Let's grab all the key/value pairs using a regular expression
36  preg_match_all('/([\w:-]+)[\s]?=[\s]?"([^"]*)"/i', $string, $attr);
37 
38  if (is_array($attr))
39  {
40  $numPairs = count($attr[1]);
41 
42  for ($i = 0; $i < $numPairs; $i++)
43  {
44  $retarray[$attr[1][$i]] = $attr[2][$i];
45  }
46  }
47 
48  return $retarray;
49  }
50 }