You are here

function extract_php in Custom Breadcrumbs 7.2

Same name and namespace in other branches
  1. 6.2 custom_breadcrumbs.module \extract_php()

Determines if a text string is php code and if it is, evaluate it.

@codingStandardsIgnoreStart

Parameters

string $text: A potential code snippet to evaluate.

array $objs: An optional array of objects to make available to the php code snippet.

Return value

string If the text string contains a php code snippet, it will be evaluated, and if the result is an array, it will be returned. Otherwise nothing is returned.

1 call to extract_php()
_custom_breadcrumbs_get_breadcrumb in ./custom_breadcrumbs.module
Gets the custom breadcrumb.

File

./custom_breadcrumbs.module, line 1294
Main file for the Custom breadcrumbs.

Code

function extract_php($text, $objs = array()) {

  // @codingStandardsIgnoreEnd
  if (drupal_substr(trim($text), 0, 5) == '<?php') {

    // Strip php tags.
    $text = str_replace(array(
      '<?php',
      '?>',
    ), '', $text);
    foreach ($objs as $key => $obj) {

      // @codingStandardsIgnoreLine
      ${$key} = is_object($obj) ? clone $obj : $obj;
    }
    ob_start();

    // @codingStandardsIgnoreLine
    $output = eval($text);
    ob_end_clean();
    return is_array($output) ? $output : NULL;
  }
}