You are here

function _xbbcode_parse_args in Extensible BBCode 5

Same name and namespace in other branches
  1. 6 xbbcode.inc \_xbbcode_parse_args()
1 call to _xbbcode_parse_args()
XBBCodeFilter::generate_tag in ./xbbcode-filter.php

File

./xbbcode-misc.php, line 74

Code

function _xbbcode_parse_args($args) {
  $args = str_replace(array(
    "\\\"",
    '\\\'',
  ), array(
    "\"",
    '\'',
  ), $args);
  if (!$args) {
    return;
  }

  // return if they don't exist.
  if ($args[0] == '=') {
    return substr($args, 1);
  }
  else {
    $args = substr($args, 1);
  }

  // otherwise, remove leading space
  $otc = _xbbcode_one_time_code($args);

  // generate our non-colliding one-time-code.
  // first, if there are quoted strings anywhere, strip quotes and escape spaces inside.
  $args = preg_replace('/"([^"]*)"|\'([^\']*)\'/e', 'str_replace(\' \',"[space-' . $otc . ']","$1$2")', $args);

  // now we have a simple space-separated text.
  $args = split(" +", $args);
  foreach ($args as $assignment) {
    if (!preg_match('/^([a-z]+)=(.*)$/', $line, $match)) {
      continue;
    }
    $parsed[$match[1]] = str_replace("[space-{$otc}]", ' ', $match[2]);
  }
  return $parsed;
}