public static function XBBCodeParser::parseAttributes in Extensible BBCode 4.0.x
Same name and namespace in other branches
- 8.3 src/Parser/XBBCodeParser.php \Drupal\xbbcode\Parser\XBBCodeParser::parseAttributes()
Parse a string of attribute assignments.
Parameters
string $argument: The string containing the attributes, including initial whitespace.
Return value
string[] An associative array of all attributes.
1 call to XBBCodeParser::parseAttributes()
- TagElement::__construct in src/
Parser/ Tree/ TagElement.php - TagElement constructor.
File
- src/
Parser/ XBBCodeParser.php, line 126
Class
- XBBCodeParser
- The standard XBBCode parser.
Namespace
Drupal\xbbcode\ParserCode
public static function parseAttributes(string $argument) : array {
$assignments = [];
preg_match_all("/\n (?<=\\s) # preceded by whitespace.\n (?'key'[\\w-]+)=\n (?:\n (?'quote'['\"]|"|&\\#039;) # quotes may be encoded.\n (?'value'\n (?:\\\\.|(?!\\\\|\\k'quote')[^\\\\])* # value can contain the delimiter.\n )\n \\k'quote'\n |\n (?'unquoted'\n (?!\\g'quote') # unquoted values cannot start with a quote.\n (?:\\\\.|[^\\s\\\\])*\n )\n )\n (?=\\s|\$)/x", $argument, $assignments, PREG_SET_ORDER);
$attributes = [];
foreach ($assignments as $assignment) {
// Strip backslashes from the escape sequences in each case.
$value = $assignment['value'] ?: $assignment['unquoted'];
$attributes[$assignment['key']] = stripslashes($value);
}
return $attributes;
}