From: <var...@us...> - 2009-01-01 19:47:36
|
Revision: 6358 http://phpwiki.svn.sourceforge.net/phpwiki/?rev=6358&view=rev Author: vargenau Date: 2009-01-01 19:47:30 +0000 (Thu, 01 Jan 2009) Log Message: ----------- New function: parse_attributes (from RichTable and MediawikiTable plugins) Modified Paths: -------------- trunk/lib/stdlib.php Modified: trunk/lib/stdlib.php =================================================================== --- trunk/lib/stdlib.php 2009-01-01 19:37:23 UTC (rev 6357) +++ trunk/lib/stdlib.php 2009-01-01 19:47:30 UTC (rev 6358) @@ -1,6 +1,7 @@ <?php //rcs_id('$Id$'); /* Copyright 1999-2008 $ThePhpWikiProgrammingTeam + Copyright 2008 Marc-Etienne Vargenau, Alcatel-Lucent This file is part of PhpWiki. @@ -2301,6 +2302,31 @@ return (!empty($s) and (strlen($s) > 3) and (substr($s,1,1) == ':')); } +/** + * Take a string and return an array of pairs (attribute name, attribute value) + * + * We allow attributes with or without double quotes (") + * Attribute-value pairs may be separated by space or comma + * border=1, cellpadding="5" + * border=1 cellpadding="5" + * style="font-family: sans-serif; border-top:1px solid #dddddd;" + * What will not work is style with comma inside, e. g. + / style="font-family: Verdana, Arial, Helvetica, sans-serif" + */ +function parse_attributes($line) { + $line = strtolower($line); + $line = str_replace(",", "", $line); + $attr_chunks = preg_split("/\s* \s*/", $line); + $options = array(); + foreach ($attr_chunks as $attr_pair) { + if (empty($attr_pair)) continue; + $key_val = preg_split("/\s*=\s*/", $attr_pair); + if (!empty($key_val[1])) + $options[trim($key_val[0])] = trim(str_replace("\"", "", $key_val[1])); + } + return $options; +} + // (c-file-style: "gnu") // Local Variables: // mode: php This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |