You are here

function google_json_text_replacement in Site Audit 7

Same name and namespace in other branches
  1. 8.2 Check/FrontEnd/GooglePageSpeed.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()
SiteAuditCheckInsightsAnalyze::getResultPass in Check/Insights/Analyze.php
Implements \SiteAudit\Check\Abstract\getResultPass().

File

Check/Insights/Analyze.php, line 303
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_sprintf = preg_replace('/\\$\\d/', '%s', $format);
  $values = array();
  foreach ($args as $arg) {
    $values[] = $arg->value;
  }
  return vsprintf($format_sprintf, $values);
}