You are here

function semanticviews_extract_attributes in Semantic Views 8.2

Extract the attributes from string to an array.

Parameters

string $string: String containing the attributes key and values.

Return value

array Array with attribute as key and the value.

2 calls to semanticviews_extract_attributes()
template_preprocess_semanticviews_row in ./semanticviews.module
Todo.
template_preprocess_semanticviews_style in ./semanticviews.module
Display the simple view of rows one after another.

File

./semanticviews.module, line 21
Semantic Views module file.

Code

function semanticviews_extract_attributes($string) {
  $values = [];
  $list = explode("\n", $string);
  $list = array_map('trim', $list);
  $list = array_filter($list, 'strlen');
  foreach ($list as $text) {

    // Check for an explicit key.
    $matches = [];
    if (preg_match('/(.*)\\|(.*)/', $text, $matches)) {

      // Trim key and value to avoid unwanted spaces issues.
      $key = trim($matches[1]);
      $value = trim($matches[2]);
    }
    else {
      $key = $value = $text;
    }
    $values[$key] = $value;
  }
  return $values;
}