You are here

function google_json_text_replacement in Site Audit 8.2

Same name and namespace in other branches
  1. 7 Check/Insights/Analyze.php \google_json_text_replacement()

Perform brute force variable replacement on a Google formatted string.

Parameters

string $format: Content to be formatted.

array $args: Optional; contains standard objects.

Return value

string Human readable formatted content.

1 call to google_json_text_replacement()
SiteAuditCheckFrontEndGooglePageSpeed::renderResults in Check/FrontEnd/GooglePageSpeed.php
Returns the rendered result from JSON decoded object.

File

Check/FrontEnd/GooglePageSpeed.php, line 403
Contains \SiteAudit\Check\Insights\Analyze.

Code

function google_json_text_replacement($format, $args = array()) {
  if (!$args || empty($args)) {
    return $format;
  }

  // If there's a better way of doing this, please let me know.
  $format = preg_replace('/\\{\\{((BEGIN_LINK)|(END_LINK))\\}\\}/', '', $format);
  $format_sprintf = preg_replace('/\\{\\{(.*?)\\}\\}/', '%s', $format);
  $values = array();
  foreach ($args as $arg) {
    $values[] = $arg->value;
  }
  return vsprintf($format_sprintf, $values);
}